home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume26 / most-3.2 / part02 < prev    next >
Encoding:
Text File  |  1993-04-12  |  79.1 KB  |  3,352 lines

  1. Newsgroups: comp.sources.unix
  2. From: davis@pacific.mps.ohio-state.edu (John E. Davis)
  3. Subject: v26i149: most-3.2 -- more/less replacement, V3.2, Part02/02
  4. Sender: unix-sources-moderator@vix.com
  5. Approved: paul@vix.com
  6.  
  7. Submitted-By: davis@pacific.mps.ohio-state.edu (John E. Davis)
  8. Posting-Number: Volume 26, Issue 149
  9. Archive-Name: most-3.2/part02
  10.  
  11. #! /bin/sh
  12. # This is a shell archive.  Remove anything before this line, then unpack
  13. # it by saving it into a file and typing "sh file".  To overwrite existing
  14. # files, type "sh file -c".  You can also feed this as standard input via
  15. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  16. # will see the following message at the end:
  17. #        "End of archive 2 (of 2)."
  18. # Contents:  keym.c most.1 sysdep.c window.c
  19. # Wrapped by vixie@gw.home.vix.com on Tue Apr 13 13:04:53 1993
  20. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  21. if test -f 'keym.c' -a "${1}" != "-c" ; then 
  22.   echo shar: Will not clobber existing file \"'keym.c'\"
  23. else
  24. echo shar: Extracting \"'keym.c'\" \(32690 characters\)
  25. sed "s/^X//" >'keym.c' <<'END_OF_FILE'
  26. X#include <stdio.h>
  27. X#include "externs.h"  
  28. X#include "keym.h"
  29. X#include "sysdep.h"
  30. X#include "display.h"
  31. X#include "buffer.h"
  32. X#include "window.h"
  33. X#include "search.h"
  34. X
  35. int *DIGIT_ARG;
  36. char LAST_CHAR;
  37. int EDT_DIRECTION = 1;
  38. X
  39. void (*root_map[128])() =
  40. X  {
  41. X      beep_cmd,                 /* ^@ */
  42. X      beep_cmd,                 /* ^A */
  43. X      beep_cmd,                 /* ^B */
  44. X      beep_cmd,                 /* ^C */
  45. X      page_down_cmd,            /* ^D */
  46. X      beep_cmd, /* ^E */
  47. X      search_cmd,               /* ^F */
  48. X      beep_cmd, /* ^G */
  49. X      help_cmd,                 /* ^H */
  50. X      page_right_cmd,           /* ^I */
  51. X      next_line_cmd,            /* ^J */
  52. X      ctrl_k_map_cmd,           /* ^K */
  53. X      beep_cmd, /* ^L */
  54. X      next_line_cmd,            /* ^M */
  55. X      next_line_cmd,            /* ^N */
  56. X      beep_cmd, /* ^O */
  57. X      previous_line_cmd,        /* ^P */
  58. X      beep_cmd, /* ^Q */
  59. X      redraw_cmd,               /* ^R */
  60. X      beep_cmd, /* ^S */
  61. X      time_cmd,                 /* ^T */
  62. X      page_up_cmd,              /* ^U */
  63. X      page_down_cmd,            /* ^V */
  64. X      ctrl_w_map_cmd,           /* ^W */
  65. X      ctrl_x_map_cmd,           /* ^X */
  66. X      beep_cmd, /* ^Y */
  67. X      sys_spawn_cmd,            /* ^Z */
  68. X      esc_map_cmd,              /* ^[ */
  69. X      beep_cmd, /* ^\ */
  70. X      beep_cmd, /* ^] */
  71. X      beep_cmd, /* ^^ */
  72. X      beep_cmd, /* ^_ */
  73. X      page_down_cmd,            /*   */
  74. X      beep_cmd, /* ! */
  75. X      beep_cmd, /* " */
  76. X      beep_cmd, /* # */
  77. X      sys_spawn_cmd,            /* $ */
  78. X      goto_percent_cmd,         /* % */
  79. X      beep_cmd, /* & */
  80. X      beep_cmd, /* ' */
  81. X      beep_cmd, /* ( */
  82. X      beep_cmd, /* ) */
  83. X      beep_cmd, /* * */
  84. X      beep_cmd, /* + */
  85. X      goto_mark_cmd,            /* , */
  86. X      digit_arg_cmd,            /* - */
  87. X      beep_cmd, /* . */
  88. X      search_cmd,               /* / */
  89. X      digit_arg_cmd,            /* 0 */
  90. X      digit_arg_cmd,            /* 1 */
  91. X      digit_arg_cmd,            /* 2 */
  92. X      digit_arg_cmd,            /* 3 */
  93. X      digit_arg_cmd,            /* 4 */
  94. X      digit_arg_cmd,            /* 5 */
  95. X      digit_arg_cmd,            /* 6 */
  96. X      digit_arg_cmd,            /* 7 */
  97. X      digit_arg_cmd,            /* 8 */
  98. X      digit_arg_cmd,            /* 9 */
  99. X      extended_key_cmd,         /* : */
  100. X      beep_cmd, /* ; */
  101. X      page_left_cmd,            /* < */
  102. X      beep_cmd, /* = */
  103. X      page_right_cmd,           /* > */
  104. X      search_back_cmd,          /* ? */
  105. X      beep_cmd, /* @ */
  106. X      beep_cmd, /* A */
  107. X      end_of_buffer_cmd,        /* B */
  108. X      beep_cmd, /* C */
  109. X      page_down_cmd,            /* D */
  110. X      edit_cmd, /* E */
  111. X      search_cmd,               /* F */
  112. X      goto_line_cmd,            /* G */
  113. X      help_cmd,                 /* H */
  114. X      beep_cmd, /* I */
  115. X      goto_line_cmd,            /* J */
  116. X      beep_cmd, /* K */
  117. X      toggle_lock,              /* L */
  118. X      set_mark_cmd,             /* M */
  119. X      find_next_cmd,            /* N */
  120. X      other_window_cmd,         /* O */
  121. X      beep_cmd, /* P */
  122. X      exit_cmd,                 /* Q */
  123. X      redraw_cmd,               /* R */
  124. X      beep_cmd, /* S */
  125. X      top_of_buffer_cmd,        /* T */
  126. X      page_up_cmd,              /* U */
  127. X      next_line_cmd,            /* V */
  128. X      toggle_width_cmd,         /* W */
  129. X      exit_cmd, /* X */
  130. X      beep_cmd, /* Y */
  131. X      beep_cmd, /* Z */
  132. X      beep_cmd, /* [ */
  133. X      beep_cmd, /* \ */
  134. X      beep_cmd, /* ] */
  135. X      beep_cmd, /* ^ */
  136. X      beep_cmd, /* _ */
  137. X      beep_cmd, /* ` */
  138. X      beep_cmd, /* a */
  139. X      end_of_buffer_cmd,        /* b */
  140. X      beep_cmd, /* c */
  141. X      page_down_cmd,            /* d */
  142. X      edit_cmd, /* e */
  143. X      search_cmd,               /* f */
  144. X      goto_line_cmd,            /* g */
  145. X      help_cmd,                 /* h */
  146. X      beep_cmd, /* i */
  147. X      goto_line_cmd,            /* j */
  148. X      beep_cmd, /* k */
  149. X      toggle_lock,              /* l */
  150. X      set_mark_cmd,             /* m */
  151. X      find_next_cmd,            /* n */
  152. X      other_window_cmd,         /* o */
  153. X      beep_cmd, /* p */
  154. X      exit_cmd,                 /* q */
  155. X      redraw_cmd,               /* r */
  156. X      beep_cmd, /* s */
  157. X      top_of_buffer_cmd,        /* t */
  158. X      page_up_cmd,              /* u */
  159. X      next_line_cmd,            /* v */
  160. X      toggle_width_cmd,         /* w */
  161. X      exit_cmd, /* x */
  162. X      beep_cmd, /* y */
  163. X      beep_cmd, /* z */
  164. X      beep_cmd, /* { */
  165. X      beep_cmd, /* | */
  166. X      beep_cmd, /* } */
  167. X      beep_cmd, /* ~ */
  168. X      page_up_cmd               /* ^? */
  169. X    };
  170. X
  171. X/*  escape map  */
  172. void (*escape_map[128])() =
  173. X  {
  174. X      beep_cmd, /* ^@ */
  175. X      beep_cmd, /* ^A */
  176. X      beep_cmd, /* ^B */
  177. X      beep_cmd, /* ^C */
  178. X      beep_cmd, /* ^D */
  179. X      beep_cmd, /* ^E */
  180. X      beep_cmd, /* ^F */
  181. X      beep_cmd, /* ^G */
  182. X      beep_cmd, /* ^H */
  183. X      beep_cmd, /* ^I */
  184. X      beep_cmd, /* ^J */
  185. X      beep_cmd, /* ^K */
  186. X      beep_cmd, /* ^L */
  187. X      beep_cmd, /* ^M */
  188. X      beep_cmd, /* ^N */
  189. X      beep_cmd, /* ^O */
  190. X      beep_cmd, /* ^P */
  191. X      beep_cmd, /* ^Q */
  192. X      beep_cmd, /* ^R */
  193. X      beep_cmd, /* ^S */
  194. X      beep_cmd, /* ^T */
  195. X      beep_cmd, /* ^U */
  196. X      beep_cmd, /* ^V */
  197. X      beep_cmd, /* ^W */
  198. X      beep_cmd, /* ^X */
  199. X      beep_cmd, /* ^Y */
  200. X      beep_cmd, /* ^Z */
  201. X      beep_cmd, /* ^[ */
  202. X      beep_cmd, /* ^\ */
  203. X      beep_cmd, /* ^] */
  204. X      beep_cmd, /* ^^ */
  205. X      beep_cmd, /* ^_ */
  206. X      beep_cmd, /*   */
  207. X      beep_cmd, /* ! */
  208. X      beep_cmd, /* " */
  209. X      beep_cmd, /* # */
  210. X      sys_spawn_cmd,            /* $ */
  211. X      beep_cmd, /* % */
  212. X      beep_cmd, /* & */
  213. X      beep_cmd, /* ' */
  214. X      beep_cmd, /* ( */
  215. X      beep_cmd, /* ) */
  216. X      beep_cmd, /* * */
  217. X      beep_cmd, /* + */
  218. X      beep_cmd, /* , */
  219. X      digit_arg_cmd,            /* - */
  220. X      beep_cmd, /* . */
  221. X      beep_cmd, /* / */
  222. X      beep_cmd, /* 0 */
  223. X      digit_arg_cmd,            /* 1 */
  224. X      digit_arg_cmd,            /* 2 */
  225. X      digit_arg_cmd,            /* 3 */
  226. X      digit_arg_cmd,            /* 4 */
  227. X      digit_arg_cmd,            /* 5 */
  228. X      digit_arg_cmd,            /* 6 */
  229. X      digit_arg_cmd,            /* 7 */
  230. X      digit_arg_cmd,            /* 8 */
  231. X      digit_arg_cmd,            /* 9 */
  232. X      beep_cmd, /* : */
  233. X      beep_cmd, /* ; */
  234. X      beep_cmd, /* < */
  235. X      beep_cmd, /* = */
  236. X      beep_cmd, /* > */
  237. X      beep_cmd, /* ? */
  238. X      beep_cmd, /* @ */
  239. X      beep_cmd, /* A */
  240. X      beep_cmd, /* B */
  241. X      beep_cmd, /* C */
  242. X      beep_cmd, /* D */
  243. X      beep_cmd, /* E */
  244. X      beep_cmd, /* F */
  245. X      beep_cmd, /* G */
  246. X      beep_cmd, /* H */
  247. X      beep_cmd, /* I */
  248. X      beep_cmd, /* J */
  249. X      beep_cmd, /* K */
  250. X      beep_cmd, /* L */
  251. X      beep_cmd, /* M */
  252. X      beep_cmd, /* N */
  253. X      O_map_cmd,                /* O */
  254. X      beep_cmd, /* P */
  255. X      beep_cmd, /* Q */
  256. X      beep_cmd, /* R */
  257. X      beep_cmd, /* S */
  258. X      beep_cmd, /* T */
  259. X      beep_cmd, /* U */
  260. X      beep_cmd, /* V */
  261. X      beep_cmd, /* W */
  262. X      extended_cmd_cmd,         /* X */
  263. X      beep_cmd, /* Y */
  264. X      beep_cmd, /* Z */
  265. X      O_map_cmd,                /* [ */
  266. X      beep_cmd, /* \ */
  267. X      beep_cmd, /* ] */
  268. X      beep_cmd, /* ^ */
  269. X      beep_cmd, /* _ */
  270. X      beep_cmd, /* ` */
  271. X      beep_cmd, /* a */
  272. X      beep_cmd, /* b */
  273. X      beep_cmd, /* c */
  274. X      beep_cmd, /* d */
  275. X      beep_cmd, /* e */
  276. X      beep_cmd, /* f */
  277. X      beep_cmd, /* g */
  278. X      beep_cmd, /* h */
  279. X      beep_cmd, /* i */
  280. X      beep_cmd, /* j */
  281. X      beep_cmd, /* k */
  282. X      beep_cmd, /* l */
  283. X      beep_cmd, /* m */
  284. X      beep_cmd, /* n */
  285. X      beep_cmd, /* o */
  286. X      beep_cmd, /* p */
  287. X      beep_cmd, /* q */
  288. X      beep_cmd, /* r */
  289. X      beep_cmd, /* s */
  290. X      beep_cmd, /* t */
  291. X      beep_cmd, /* u */
  292. X      beep_cmd, /* v */
  293. X      beep_cmd, /* w */
  294. X      extended_cmd_cmd,         /* x */
  295. X      beep_cmd, /* y */
  296. X      beep_cmd, /* z */
  297. X      beep_cmd, /* { */
  298. X      beep_cmd, /* | */
  299. X      beep_cmd, /* } */
  300. X      beep_cmd, /* ~ */
  301. X      beep_cmd  /* ^? */
  302. X  };
  303. X
  304. void (*ctrl_x_map[128])() =
  305. X  {
  306. X      beep_cmd, /* ^@ */
  307. X      beep_cmd, /* ^A */
  308. X      beep_cmd, /* ^B */
  309. X      exit_cmd, /* ^C */
  310. X      beep_cmd, /* ^D */
  311. X      beep_cmd, /* ^E */
  312. X      find_file_cmd,            /* ^F */
  313. X      beep_cmd, /* ^G */
  314. X      beep_cmd, /* ^H */
  315. X      beep_cmd, /* ^I */
  316. X      beep_cmd, /* ^J */
  317. X      beep_cmd, /* ^K */
  318. X      beep_cmd, /* ^L */
  319. X      beep_cmd, /* ^M */
  320. X      beep_cmd, /* ^N */
  321. X      beep_cmd, /* ^O */
  322. X      beep_cmd, /* ^P */
  323. X      beep_cmd, /* ^Q */
  324. X      beep_cmd, /* ^R */
  325. X      beep_cmd, /* ^S */
  326. X      beep_cmd, /* ^T */
  327. X      beep_cmd, /* ^U */
  328. X      beep_cmd, /* ^V */
  329. X      beep_cmd, /* ^W */
  330. X      beep_cmd, /* ^X */
  331. X      beep_cmd, /* ^Y */
  332. X      beep_cmd, /* ^Z */
  333. X      beep_cmd, /* ^[ */
  334. X      beep_cmd, /* ^\ */
  335. X      beep_cmd, /* ^] */
  336. X      beep_cmd, /* ^^ */
  337. X      beep_cmd, /* ^_ */
  338. X      beep_cmd, /*   */
  339. X      beep_cmd, /* ! */
  340. X      beep_cmd, /* " */
  341. X      beep_cmd, /* # */
  342. X      beep_cmd, /* $ */
  343. X      beep_cmd, /* % */
  344. X      beep_cmd, /* & */
  345. X      beep_cmd, /* ' */
  346. X      beep_cmd, /* ( */
  347. X      beep_cmd, /* ) */
  348. X      beep_cmd, /* * */
  349. X      beep_cmd, /* + */
  350. X      beep_cmd, /* , */
  351. X      beep_cmd, /* - */
  352. X      beep_cmd, /* . */
  353. X      beep_cmd, /* / */
  354. X      del_window_cmd,           /* 0 */
  355. X      one_window_cmd,           /* 1 */
  356. X      two_window_cmd,           /* 2 */
  357. X      beep_cmd, /* 3 */
  358. X      beep_cmd, /* 4 */
  359. X      beep_cmd, /* 5 */
  360. X      beep_cmd, /* 6 */
  361. X      beep_cmd, /* 7 */
  362. X      beep_cmd, /* 8 */
  363. X      beep_cmd, /* 9 */
  364. X      beep_cmd, /* : */
  365. X      beep_cmd, /* ; */
  366. X      beep_cmd, /* < */
  367. X      beep_cmd, /* = */
  368. X      beep_cmd, /* > */
  369. X      beep_cmd, /* ? */
  370. X      beep_cmd, /* @ */
  371. X      beep_cmd, /* A */
  372. X      beep_cmd, /* B */
  373. X      beep_cmd, /* C */
  374. X      beep_cmd, /* D */
  375. X      beep_cmd, /* E */
  376. X      beep_cmd, /* F */
  377. X      beep_cmd, /* G */
  378. X      beep_cmd, /* H */
  379. X      beep_cmd, /* I */
  380. X      beep_cmd, /* J */
  381. X      beep_cmd, /* K */
  382. X      beep_cmd, /* L */
  383. X      beep_cmd, /* M */
  384. X      beep_cmd, /* N */
  385. X      other_window_cmd,         /* O */
  386. X      beep_cmd, /* P */
  387. X      beep_cmd, /* Q */
  388. X      beep_cmd, /* R */
  389. X      beep_cmd, /* S */
  390. X      beep_cmd, /* T */
  391. X      beep_cmd, /* U */
  392. X      beep_cmd, /* V */
  393. X      beep_cmd, /* W */
  394. X      beep_cmd, /* X */
  395. X      beep_cmd, /* Y */
  396. X      beep_cmd, /* Z */
  397. X      beep_cmd, /* [ */
  398. X      beep_cmd, /* \ */
  399. X      beep_cmd, /* ] */
  400. X      beep_cmd, /* ^ */
  401. X      beep_cmd, /* _ */
  402. X      beep_cmd, /* ` */
  403. X      beep_cmd, /* a */
  404. X      beep_cmd, /* b */
  405. X      beep_cmd, /* c */
  406. X      beep_cmd, /* d */
  407. X      beep_cmd, /* e */
  408. X      beep_cmd, /* f */
  409. X      beep_cmd, /* g */
  410. X      beep_cmd, /* h */
  411. X      beep_cmd, /* i */
  412. X      beep_cmd, /* j */
  413. X      beep_cmd, /* k */
  414. X      beep_cmd, /* l */
  415. X      beep_cmd, /* m */
  416. X      beep_cmd, /* n */
  417. X      other_window_cmd,         /* o */
  418. X      beep_cmd, /* p */
  419. X      beep_cmd, /* q */
  420. X      beep_cmd, /* r */
  421. X      beep_cmd, /* s */
  422. X      beep_cmd, /* t */
  423. X      beep_cmd, /* u */
  424. X      beep_cmd, /* v */
  425. X      beep_cmd, /* w */
  426. X      beep_cmd, /* x */
  427. X      beep_cmd, /* y */
  428. X      beep_cmd, /* z */
  429. X      beep_cmd, /* { */
  430. X      beep_cmd, /* | */
  431. X      beep_cmd, /* } */
  432. X      beep_cmd, /* ~ */
  433. X      beep_cmd  /* ^? */
  434. X  };
  435. X
  436. void (*ctrl_w_map[128])() =
  437. X  {
  438. X      beep_cmd, /* ^@ */
  439. X      beep_cmd, /* ^A */
  440. X      beep_cmd, /* ^B */
  441. X      beep_cmd, /* ^C */
  442. X      beep_cmd, /* ^D */
  443. X      beep_cmd, /* ^E */
  444. X      beep_cmd, /* ^F */
  445. X      beep_cmd, /* ^G */
  446. X      beep_cmd, /* ^H */
  447. X      beep_cmd, /* ^I */
  448. X      beep_cmd, /* ^J */
  449. X      beep_cmd, /* ^K */
  450. X      beep_cmd, /* ^L */
  451. X      beep_cmd, /* ^M */
  452. X      beep_cmd, /* ^N */
  453. X      beep_cmd, /* ^O */
  454. X      beep_cmd, /* ^P */
  455. X      beep_cmd, /* ^Q */
  456. X      beep_cmd, /* ^R */
  457. X      beep_cmd, /* ^S */
  458. X      beep_cmd, /* ^T */
  459. X      beep_cmd, /* ^U */
  460. X      beep_cmd, /* ^V */
  461. X      beep_cmd, /* ^W */
  462. X      beep_cmd, /* ^X */
  463. X      beep_cmd, /* ^Y */
  464. X      beep_cmd, /* ^Z */
  465. X      beep_cmd, /* ^[ */
  466. X      beep_cmd, /* ^\ */
  467. X      beep_cmd, /* ^] */
  468. X      beep_cmd, /* ^^ */
  469. X      beep_cmd, /* ^_ */
  470. X      beep_cmd, /*   */
  471. X      beep_cmd, /* ! */
  472. X      beep_cmd, /* " */
  473. X      beep_cmd, /* # */
  474. X      beep_cmd, /* $ */
  475. X      beep_cmd, /* % */
  476. X      beep_cmd, /* & */
  477. X      beep_cmd, /* ' */
  478. X      beep_cmd, /* ( */
  479. X      beep_cmd, /* ) */
  480. X      beep_cmd, /* * */
  481. X      beep_cmd, /* + */
  482. X      beep_cmd, /* , */
  483. X      beep_cmd, /* - */
  484. X      beep_cmd, /* . */
  485. X      beep_cmd, /* / */
  486. X      del_window_cmd,           /* 0 */
  487. X      one_window_cmd,           /* 1 */
  488. X      two_window_cmd,           /* 2 */
  489. X      beep_cmd, /* 3 */
  490. X      beep_cmd, /* 4 */
  491. X      beep_cmd, /* 5 */
  492. X      beep_cmd, /* 6 */
  493. X      beep_cmd, /* 7 */
  494. X      beep_cmd, /* 8 */
  495. X      beep_cmd, /* 9 */
  496. X      beep_cmd, /* : */
  497. X      beep_cmd, /* ; */
  498. X      beep_cmd, /* < */
  499. X      beep_cmd, /* = */
  500. X      beep_cmd, /* > */
  501. X      beep_cmd, /* ? */
  502. X      beep_cmd, /* @ */
  503. X      beep_cmd, /* A */
  504. X      beep_cmd, /* B */
  505. X      beep_cmd, /* C */
  506. X      beep_cmd, /* D */
  507. X      beep_cmd, /* E */
  508. X      beep_cmd, /* F */
  509. X      beep_cmd, /* G */
  510. X      beep_cmd, /* H */
  511. X      beep_cmd, /* I */
  512. X      beep_cmd, /* J */
  513. X      beep_cmd, /* K */
  514. X      beep_cmd, /* L */
  515. X      beep_cmd, /* M */
  516. X      beep_cmd, /* N */
  517. X      other_window_cmd,         /* O */
  518. X      beep_cmd, /* P */
  519. X      beep_cmd, /* Q */
  520. X      beep_cmd, /* R */
  521. X      beep_cmd, /* S */
  522. X      beep_cmd, /* T */
  523. X      beep_cmd, /* U */
  524. X      beep_cmd, /* V */
  525. X      beep_cmd, /* W */
  526. X      beep_cmd, /* X */
  527. X      beep_cmd, /* Y */
  528. X      beep_cmd, /* Z */
  529. X      beep_cmd, /* [ */
  530. X      beep_cmd, /* \ */
  531. X      beep_cmd, /* ] */
  532. X      beep_cmd, /* ^ */
  533. X      beep_cmd, /* _ */
  534. X      beep_cmd, /* ` */
  535. X      beep_cmd, /* a */
  536. X      beep_cmd, /* b */
  537. X      beep_cmd, /* c */
  538. X      beep_cmd, /* d */
  539. X      beep_cmd, /* e */
  540. X      beep_cmd, /* f */
  541. X      beep_cmd, /* g */
  542. X      beep_cmd, /* h */
  543. X      beep_cmd, /* i */
  544. X      beep_cmd, /* j */
  545. X      beep_cmd, /* k */
  546. X      beep_cmd, /* l */
  547. X      beep_cmd, /* m */
  548. X      beep_cmd, /* n */
  549. X      other_window_cmd, /* o */
  550. X      beep_cmd, /* p */
  551. X      beep_cmd, /* q */
  552. X      beep_cmd, /* r */
  553. X      beep_cmd, /* s */
  554. X      beep_cmd, /* t */
  555. X      beep_cmd, /* u */
  556. X      beep_cmd, /* v */
  557. X      beep_cmd, /* w */
  558. X      beep_cmd, /* x */
  559. X      beep_cmd, /* y */
  560. X      beep_cmd, /* z */
  561. X      beep_cmd, /* { */
  562. X      beep_cmd, /* | */
  563. X      beep_cmd, /* } */
  564. X      beep_cmd, /* ~ */
  565. X      beep_cmd  /* ^? */
  566. X  };
  567. X
  568. void (*ctrl_k_map[128])() =
  569. X  {
  570. X      beep_cmd, /* ^@ */
  571. X      beep_cmd, /* ^A */
  572. X      set_mark_cmd,             /* ^B */
  573. X      beep_cmd, /* ^C */
  574. X      beep_cmd, /* ^D */
  575. X      beep_cmd, /* ^E */
  576. X      beep_cmd, /* ^F */
  577. X      beep_cmd, /* ^G */
  578. X      beep_cmd, /* ^H */
  579. X      beep_cmd, /* ^I */
  580. X      goto_mark_cmd,            /* ^J */
  581. X      beep_cmd, /* ^K */
  582. X      beep_cmd, /* ^L */
  583. X      goto_mark_cmd,            /* ^M */
  584. X      beep_cmd, /* ^N */
  585. X      beep_cmd, /* ^O */
  586. X      beep_cmd, /* ^P */
  587. X      beep_cmd, /* ^Q */
  588. X      beep_cmd, /* ^R */
  589. X      beep_cmd, /* ^S */
  590. X      beep_cmd, /* ^T */
  591. X      beep_cmd, /* ^U */
  592. X      beep_cmd, /* ^V */
  593. X      beep_cmd, /* ^W */
  594. X      beep_cmd, /* ^X */
  595. X      beep_cmd, /* ^Y */
  596. X      beep_cmd, /* ^Z */
  597. X      beep_cmd, /* ^[ */
  598. X      beep_cmd, /* ^\ */
  599. X      beep_cmd, /* ^] */
  600. X      beep_cmd, /* ^^ */
  601. X      beep_cmd, /* ^_ */
  602. X      beep_cmd, /*   */
  603. X      beep_cmd, /* ! */
  604. X      beep_cmd, /* " */
  605. X      beep_cmd, /* # */
  606. X      beep_cmd, /* $ */
  607. X      beep_cmd, /* % */
  608. X      beep_cmd, /* & */
  609. X      beep_cmd, /* ' */
  610. X      beep_cmd, /* ( */
  611. X      beep_cmd, /* ) */
  612. X      beep_cmd, /* * */
  613. X      beep_cmd, /* + */
  614. X      beep_cmd, /* , */
  615. X      beep_cmd, /* - */
  616. X      beep_cmd, /* . */
  617. X      beep_cmd, /* / */
  618. X      beep_cmd, /* 0 */
  619. X      beep_cmd, /* 1 */
  620. X      beep_cmd, /* 2 */
  621. X      beep_cmd, /* 3 */
  622. X      beep_cmd, /* 4 */
  623. X      beep_cmd, /* 5 */
  624. X      beep_cmd, /* 6 */
  625. X      beep_cmd, /* 7 */
  626. X      beep_cmd, /* 8 */
  627. X      beep_cmd, /* 9 */
  628. X      beep_cmd, /* : */
  629. X      beep_cmd, /* ; */
  630. X      beep_cmd, /* < */
  631. X      beep_cmd, /* = */
  632. X      beep_cmd, /* > */
  633. X      beep_cmd, /* ? */
  634. X      beep_cmd, /* @ */
  635. X      beep_cmd, /* A */
  636. X      beep_cmd, /* B */
  637. X      beep_cmd, /* C */
  638. X      extended_cmd_cmd,         /* D */
  639. X      exit_cmd,                 /* E */
  640. X      beep_cmd, /* F */
  641. X      find_file_cmd,            /* G */
  642. X      beep_cmd, /* H */
  643. X      beep_cmd, /* I */
  644. X      beep_cmd, /* J */
  645. X      beep_cmd, /* K */
  646. X      beep_cmd, /* L */
  647. X      set_mark_cmd,             /* M */
  648. X      beep_cmd, /* N */
  649. X      beep_cmd, /* O */
  650. X      beep_cmd, /* P */
  651. X      beep_cmd, /* Q */
  652. X      beep_cmd, /* R */
  653. X      beep_cmd, /* S */
  654. X      beep_cmd, /* T */
  655. X      beep_cmd, /* U */
  656. X      beep_cmd, /* V */
  657. X      beep_cmd, /* W */
  658. X      beep_cmd, /* X */
  659. X      beep_cmd, /* Y */
  660. X      beep_cmd, /* Z */
  661. X      beep_cmd, /* [ */
  662. X      beep_cmd, /* \ */
  663. X      beep_cmd, /* ] */
  664. X      beep_cmd, /* ^ */
  665. X      beep_cmd, /* _ */
  666. X      beep_cmd, /* ` */
  667. X      beep_cmd, /* a */
  668. X      beep_cmd, /* b */
  669. X      beep_cmd, /* c */
  670. X      extended_cmd_cmd,         /* d */
  671. X      exit_cmd,                 /* e */
  672. X      beep_cmd, /* f */
  673. X      find_file_cmd,            /* g */
  674. X      beep_cmd, /* h */
  675. X      beep_cmd, /* i */
  676. X      beep_cmd, /* j */
  677. X      beep_cmd, /* k */
  678. X      beep_cmd, /* l */
  679. X      set_mark_cmd,             /* m */
  680. X      beep_cmd, /* n */
  681. X      beep_cmd, /* o */
  682. X      beep_cmd, /* p */
  683. X      beep_cmd, /* q */
  684. X      beep_cmd, /* r */
  685. X      beep_cmd, /* s */
  686. X      beep_cmd, /* t */
  687. X      beep_cmd, /* u */
  688. X      beep_cmd, /* v */
  689. X      beep_cmd, /* w */
  690. X      beep_cmd, /* x */
  691. X      beep_cmd, /* y */
  692. X      beep_cmd, /* z */
  693. X      beep_cmd, /* { */
  694. X      beep_cmd, /* | */
  695. X      beep_cmd, /* } */
  696. X      beep_cmd, /* ~ */
  697. X      beep_cmd  /* ^? */
  698. X  };
  699. X
  700. void (*esc_O_map[128])() =
  701. X  {
  702. X      beep_cmd, /* ^@ */
  703. X      beep_cmd, /* ^A */
  704. X      beep_cmd, /* ^B */
  705. X      beep_cmd, /* ^C */
  706. X      beep_cmd, /* ^D */
  707. X      beep_cmd, /* ^E */
  708. X      beep_cmd, /* ^F */
  709. X      beep_cmd, /* ^G */
  710. X      beep_cmd, /* ^H */
  711. X      beep_cmd, /* ^I */
  712. X      beep_cmd, /* ^J */
  713. X      beep_cmd, /* ^K */
  714. X      beep_cmd, /* ^L */
  715. X      beep_cmd, /* ^M */
  716. X      beep_cmd, /* ^N */
  717. X      beep_cmd, /* ^O */
  718. X      beep_cmd, /* ^P */
  719. X      beep_cmd, /* ^Q */
  720. X      beep_cmd, /* ^R */
  721. X      beep_cmd, /* ^S */
  722. X      beep_cmd, /* ^T */
  723. X      beep_cmd, /* ^U */
  724. X      beep_cmd, /* ^V */
  725. X      beep_cmd, /* ^W */
  726. X      beep_cmd, /* ^X */
  727. X      beep_cmd, /* ^Y */
  728. X      beep_cmd, /* ^Z */
  729. X      beep_cmd, /* ^[ */
  730. X      beep_cmd, /* ^\ */
  731. X      beep_cmd, /* ^] */
  732. X      beep_cmd, /* ^^ */
  733. X      beep_cmd, /* ^_ */
  734. X      beep_cmd, /*   */
  735. X      beep_cmd, /* ! */
  736. X      beep_cmd, /* " */
  737. X      beep_cmd, /* # */
  738. X      beep_cmd, /* $ */
  739. X      beep_cmd, /* % */
  740. X      beep_cmd, /* & */
  741. X      beep_cmd, /* ' */
  742. X      beep_cmd, /* ( */
  743. X      beep_cmd, /* ) */
  744. X      beep_cmd, /* * */
  745. X      beep_cmd, /* + */
  746. X      beep_cmd, /* , */
  747. X      beep_cmd, /* - */
  748. X      beep_cmd, /* . */
  749. X      beep_cmd, /* / */
  750. X      dec_extended_map_cmd,     /* 0 */
  751. X      dec_extended_map_cmd,     /* 1 */
  752. X      dec_extended_map_cmd,     /* 2 */
  753. X      dec_extended_map_cmd,     /* 3 */
  754. X      dec_extended_map_cmd,     /* 4 */
  755. X      dec_extended_map_cmd,     /* 5 */
  756. X      dec_extended_map_cmd,     /* 6 */
  757. X      dec_extended_map_cmd,     /* 7 */
  758. X      dec_extended_map_cmd,     /* 8 */
  759. X      dec_extended_map_cmd,     /* 9 */
  760. X      beep_cmd, /* : */
  761. X      beep_cmd, /* ; */
  762. X      beep_cmd, /* < */
  763. X      beep_cmd, /* = */
  764. X      beep_cmd, /* > */
  765. X      beep_cmd, /* ? */
  766. X      beep_cmd, /* @ */
  767. X      previous_line_cmd,        /* A */
  768. X      next_line_cmd,            /* B */
  769. X      page_right_cmd,           /* C */
  770. X      page_left_cmd,            /* D */
  771. X      beep_cmd, /* E */
  772. X      beep_cmd, /* F */
  773. X      beep_cmd, /* G */
  774. X      beep_cmd, /* H */
  775. X      beep_cmd, /* I */
  776. X      beep_cmd, /* J */
  777. X      beep_cmd, /* K */
  778. X      beep_cmd, /* L */
  779. X      next_line_cmd, /* M */
  780. X      beep_cmd, /* N */
  781. X      beep_cmd, /* O */
  782. X      pf1_map_cmd, /* P */    /* PF1 */
  783. X      help_cmd, /* Q */ /* PF2 */
  784. X      edt_find_next_cmd, /* R */ /* PF3 */
  785. X      beep_cmd, /* S */ /* PF4 */
  786. X      beep_cmd, /* T */
  787. X      beep_cmd, /* U */
  788. X      beep_cmd, /* V */
  789. X      beep_cmd, /* W */
  790. X      beep_cmd, /* X */
  791. X      beep_cmd, /* Y */
  792. X      beep_cmd, /* Z */
  793. X      beep_cmd, /* [ */
  794. X      beep_cmd, /* \ */
  795. X      beep_cmd, /* ] */
  796. X      beep_cmd, /* ^ */
  797. X      beep_cmd, /* _ */
  798. X      beep_cmd, /* ` */
  799. X      beep_cmd, /* a */
  800. X      beep_cmd, /* b */
  801. X      beep_cmd, /* c */
  802. X      beep_cmd, /* d */
  803. X      beep_cmd, /* e */
  804. X      beep_cmd, /* f */
  805. X      beep_cmd, /* g */
  806. X      beep_cmd, /* h */
  807. X      beep_cmd, /* i */
  808. X      beep_cmd, /* j */
  809. X      beep_cmd, /* k */
  810. X      beep_cmd, /* l */
  811. X      beep_cmd, /* m */
  812. X      set_mark_cmd, /* n */
  813. X      beep_cmd, /* o */
  814. X      edt_line_cmd, /* p */ /* KP0 */
  815. X      beep_cmd, /* q */ /* KP1 */
  816. X      beep_cmd, /* r */ /* KP2 */
  817. X      beep_cmd, /* s */ /* KP3 */
  818. X      edt_forward_cmd, /* t */ /* KP4 */
  819. X      edt_back_cmd, /* u */ /* KP5 */
  820. X      beep_cmd, /* v */ /* KP6 */
  821. X      beep_cmd, /* w */ /* KP7 */
  822. X      edt_page_cmd, /* x */ /* KP8 */
  823. X      beep_cmd, /* y */ /* KP9 */
  824. X      beep_cmd, /* z */
  825. X      beep_cmd, /* { */
  826. X      beep_cmd, /* | */
  827. X      beep_cmd, /* } */
  828. X      beep_cmd, /* ~ */
  829. X      beep_cmd  /* ^? */
  830. X  };
  831. X
  832. void (*pf1_map[128])() =    /* Gold */
  833. X  {
  834. X      beep_cmd, /* ^@ */
  835. X      beep_cmd, /* ^A */
  836. X      beep_cmd, /* ^B */
  837. X      beep_cmd, /* ^C */
  838. X      beep_cmd, /* ^D */
  839. X      beep_cmd, /* ^E */
  840. X      beep_cmd, /* ^F */
  841. X      beep_cmd, /* ^G */
  842. X      beep_cmd, /* ^H */
  843. X      beep_cmd, /* ^I */
  844. X      beep_cmd, /* ^J */
  845. X      beep_cmd, /* ^K */
  846. X      beep_cmd, /* ^L */
  847. X      beep_cmd, /* ^M */
  848. X      beep_cmd, /* ^N */
  849. X      beep_cmd, /* ^O */
  850. X      beep_cmd, /* ^P */
  851. X      beep_cmd, /* ^Q */
  852. X      beep_cmd, /* ^R */
  853. X      beep_cmd, /* ^S */
  854. X      beep_cmd, /* ^T */
  855. X      beep_cmd, /* ^U */
  856. X      beep_cmd, /* ^V */
  857. X      beep_cmd, /* ^W */
  858. X      beep_cmd, /* ^X */
  859. X      beep_cmd, /* ^Y */
  860. X      beep_cmd, /* ^Z */
  861. X      pf1_esc_map_cmd, /* ^[ */
  862. X      beep_cmd, /* ^\ */
  863. X      beep_cmd, /* ^] */
  864. X      beep_cmd, /* ^^ */
  865. X      beep_cmd, /* ^_ */
  866. X      beep_cmd, /*   */
  867. X      beep_cmd, /* ! */
  868. X      beep_cmd, /* " */
  869. X      beep_cmd, /* # */
  870. X      beep_cmd, /* $ */
  871. X      beep_cmd, /* % */
  872. X      beep_cmd, /* & */
  873. X      beep_cmd, /* ' */
  874. X      beep_cmd, /* ( */
  875. X      beep_cmd, /* ) */
  876. X      beep_cmd, /* * */
  877. X      beep_cmd, /* + */
  878. X      beep_cmd, /* , */
  879. X      beep_cmd, /* - */
  880. X      beep_cmd, /* . */
  881. X      beep_cmd, /* / */
  882. X      digit_arg_cmd, /* 0 */
  883. X      digit_arg_cmd, /* 1 */
  884. X      digit_arg_cmd, /* 2 */
  885. X      digit_arg_cmd, /* 3 */
  886. X      digit_arg_cmd, /* 4 */
  887. X      digit_arg_cmd, /* 5 */
  888. X      digit_arg_cmd, /* 6 */
  889. X      digit_arg_cmd, /* 7 */
  890. X      digit_arg_cmd, /* 8 */
  891. X      digit_arg_cmd, /* 9 */
  892. X      beep_cmd, /* : */
  893. X      beep_cmd, /* ; */
  894. X      beep_cmd, /* < */
  895. X      beep_cmd, /* = */
  896. X      beep_cmd, /* > */
  897. X      beep_cmd, /* ? */
  898. X      beep_cmd, /* @ */
  899. X      beep_cmd, /* A */
  900. X      beep_cmd, /* B */
  901. X      beep_cmd, /* C */
  902. X      beep_cmd, /* D */
  903. X      beep_cmd, /* E */
  904. X      beep_cmd, /* F */
  905. X      beep_cmd, /* G */
  906. X      beep_cmd, /* H */
  907. X      beep_cmd, /* I */
  908. X      beep_cmd, /* J */
  909. X      beep_cmd, /* K */
  910. X      beep_cmd, /* L */
  911. X      beep_cmd, /* M */
  912. X      beep_cmd, /* N */
  913. X      one_window_cmd, /* O */
  914. X      beep_cmd, /* P */
  915. X      exit_cmd, /* Q */
  916. X      beep_cmd, /* R */
  917. X      sys_spawn_cmd, /* S */
  918. X      beep_cmd, /* T */
  919. X      beep_cmd, /* U */
  920. X      del_window_cmd, /* V */
  921. X      beep_cmd, /* W */
  922. X      two_window_cmd, /* X */
  923. X      beep_cmd, /* Y */
  924. X      beep_cmd, /* Z */
  925. X      beep_cmd, /* [ */
  926. X      beep_cmd, /* \ */
  927. X      beep_cmd, /* ] */
  928. X      beep_cmd, /* ^ */
  929. X      beep_cmd, /* _ */
  930. X      beep_cmd, /* ` */
  931. X      beep_cmd, /* a */
  932. X      beep_cmd, /* b */
  933. X      beep_cmd, /* c */
  934. X      beep_cmd, /* d */
  935. X      beep_cmd, /* e */
  936. X      beep_cmd, /* f */
  937. X      beep_cmd, /* g */
  938. X      beep_cmd, /* h */
  939. X      beep_cmd, /* i */
  940. X      beep_cmd, /* j */
  941. X      beep_cmd, /* k */
  942. X      beep_cmd, /* l */
  943. X      beep_cmd, /* m */
  944. X      beep_cmd, /* n */
  945. X      one_window_cmd, /* o */
  946. X      beep_cmd, /* p */
  947. X      exit_cmd, /* q */
  948. X      beep_cmd, /* r */
  949. X      sys_spawn_cmd, /* s */
  950. X      beep_cmd, /* t */
  951. X      beep_cmd, /* u */
  952. X      del_window_cmd, /* v */
  953. X      beep_cmd, /* w */
  954. X      two_window_cmd, /* x */
  955. X      beep_cmd, /* y */
  956. X      beep_cmd, /* z */
  957. X      beep_cmd, /* { */
  958. X      beep_cmd, /* | */
  959. X      beep_cmd, /* } */
  960. X      beep_cmd, /* ~ */
  961. X      beep_cmd  /* ^? */
  962. X  };
  963. X
  964. void execute_key()
  965. X{
  966. X    char ch;
  967. X    int r,c;
  968. X    c = CURS_COL - COLUMN + 1;
  969. X    r = CURS_ROW;
  970. X    if (MINI_BUF[0] != '\0') put_message();
  971. X    if (r < 1) r = 1;
  972. X    else if (r > (WIN->bot - WIN->top + 1))
  973. X      r = WIN->bot - WIN->top + 1;
  974. X    if (c > SCREEN_WIDTH) c = SCREEN_WIDTH;
  975. X    else if (c < 1) c = 1;
  976. X    goto_rc(r,c);
  977. X    fflush(stdout);
  978. X    DIGIT_ARG = (int *) NULL;
  979. X    ch = getkey();
  980. X    if (MINI_BUF[0] != '\0') clear_minibuffer();
  981. X    LAST_CHAR = ch;
  982. X    (*root_map[ (int) ch ])();
  983. X}
  984. X
  985. void ctrl_x_map_cmd()
  986. X{
  987. X    char ch;
  988. X
  989. X    ch = getkey();
  990. X    (*ctrl_x_map[ (int) ch ])();
  991. X}
  992. X
  993. void ctrl_k_map_cmd()
  994. X{
  995. X    char ch;
  996. X
  997. X    ch = getkey();
  998. X    (*ctrl_k_map[ (int) ch ])();
  999. X}
  1000. X
  1001. void ctrl_w_map_cmd()
  1002. X{
  1003. X    char ch;
  1004. X
  1005. X    ch = getkey();
  1006. X    (*ctrl_w_map[ (int) ch ])();
  1007. X}
  1008. X
  1009. void O_map_cmd()
  1010. X{
  1011. X    char ch;
  1012. X
  1013. X    ch = getkey();
  1014. X    LAST_CHAR = ch;
  1015. X    (*esc_O_map[ (int) ch ])();
  1016. X}
  1017. X
  1018. void esc_map_cmd()
  1019. X{
  1020. X    char ch;
  1021. X
  1022. X    ch = getkey();
  1023. X    LAST_CHAR = ch;
  1024. X    (*escape_map[ (int) ch ])();
  1025. X}
  1026. X
  1027. X/* weird sequences of form ^[[n~ where n is an integer */
  1028. void dec_extended_map_cmd()
  1029. X{
  1030. X    char ch, numstr[5];
  1031. X    int i, num;
  1032. X    
  1033. X    ch = LAST_CHAR;  /* should be integer */
  1034. X    i = 0;
  1035. X    numstr[i++] = ch;
  1036. X    while (ch = getkey(), isdigit(ch)) numstr[i++] = ch;
  1037. X    if (ch == '~')
  1038. X      {
  1039. X          numstr[i++] =  '\0';
  1040. X          sscanf(numstr,"%d",&num);
  1041. X          switch (num)
  1042. X            {
  1043. X              case 5:
  1044. X                page_up_cmd(); break; /* prev screen */
  1045. X              case 6:
  1046. X                page_down_cmd(); break; /* next screen */
  1047. X              case 1:
  1048. X                search_cmd(); break; /* find */
  1049. X              case 4:
  1050. X                set_mark_cmd(); break; /* select */
  1051. X              case 2:   
  1052. X                goto_mark_cmd(); break; /* insert here */
  1053. X              case 28:
  1054. X                help_cmd(); break; /* Help */
  1055. X              case 29:  /* do */
  1056. X                extended_cmd_cmd(); break;
  1057. X              default:
  1058. X                beep_cmd(); break;
  1059. X            }
  1060. X      }
  1061. X    else beep_cmd();
  1062. X}
  1063. X
  1064. X/* weird sequences of form ^[[n~ where n is an integer */
  1065. void pf1_esc_map_cmd()
  1066. X{
  1067. X    char ch, numstr[5];
  1068. X    int i, num;
  1069. X    
  1070. X    LAST_CHAR = ch = getkey();
  1071. X    switch (ch)
  1072. X    {
  1073. X    case 'O':
  1074. X        LAST_CHAR = ch = getkey();
  1075. X        switch (ch)
  1076. X        {
  1077. X        case 't': /* KP4 */
  1078. X            end_of_buffer_cmd(); break;
  1079. X        case 'u': /* KP5 */
  1080. X            top_of_buffer_cmd(); break;
  1081. X        case 'w': /* KP7 */
  1082. X            extended_cmd_cmd(); break;
  1083. X        case 'n': /* KP7 */
  1084. X            goto_mark_cmd(); break;
  1085. X        case 'R': /* PF3 */
  1086. X            edt_find_cmd(); break;
  1087. X        default :
  1088. X            beep_cmd(); break;
  1089. X        }
  1090. X        break;
  1091. X    case '[':
  1092. X        LAST_CHAR = ch = getkey();
  1093. X        switch (ch)
  1094. X        {
  1095. X        case 'A':
  1096. X            other_window_cmd(); break;
  1097. X        case 'B':
  1098. X            other_window_cmd(); break;
  1099. X        case 'C':
  1100. X            page_left_cmd(); break;
  1101. X        case 'D':
  1102. X            page_right_cmd(); break;
  1103. X        default :
  1104. X            beep_cmd(); break;
  1105. X        };
  1106. X        break;
  1107. X    default :
  1108. X            beep_cmd(); break;
  1109. X    }
  1110. X}
  1111. X
  1112. void pf1_map_cmd()
  1113. X{
  1114. X    char ch;
  1115. X
  1116. X    ch = getkey();
  1117. X    LAST_CHAR = ch;
  1118. X    (*pf1_map[ (int) ch ])();
  1119. X}
  1120. X
  1121. void beep_cmd()
  1122. X{
  1123. X    fputc('\007',stdout);
  1124. X}
  1125. X
  1126. void page_down_cmd()
  1127. X{
  1128. X    int n = 1;
  1129. X    if (DIGIT_ARG != (int *) NULL) n = *DIGIT_ARG;
  1130. X    update_windows(C_LINE + n * (WIN->bot - WIN->top + 1));
  1131. X}
  1132. void page_up_cmd()
  1133. X{
  1134. X    int n = 1;
  1135. X    if (DIGIT_ARG != (int *) NULL) n = *DIGIT_ARG;
  1136. X    update_windows(C_LINE - n * (WIN->bot - WIN->top + 1));
  1137. X}
  1138. X
  1139. void page_right_cmd()
  1140. X{
  1141. X    int n = 1;
  1142. X    if (DIGIT_ARG != (int *) NULL) n = *DIGIT_ARG;
  1143. X    COLUMN = COLUMN + n * 59;
  1144. X    update_windows(C_LINE);
  1145. X}
  1146. X
  1147. void page_left_cmd()
  1148. X{
  1149. X    int n = 1;
  1150. X    if (DIGIT_ARG != (int *) NULL) n = *DIGIT_ARG;
  1151. X    COLUMN = COLUMN - n * 59;
  1152. X    update_windows(C_LINE);
  1153. X}
  1154. X
  1155. void next_line_cmd()
  1156. X{
  1157. X    int n = 1;
  1158. X    if (DIGIT_ARG != (int *) NULL) n = *DIGIT_ARG;
  1159. X    update_windows(C_LINE + n);
  1160. X}
  1161. X
  1162. void previous_line_cmd()
  1163. X{
  1164. X    int n = 1;
  1165. X    if (DIGIT_ARG != (int *) NULL) n = *DIGIT_ARG;
  1166. X    update_windows(C_LINE - n);
  1167. X}
  1168. X
  1169. void top_of_buffer_cmd()
  1170. X{
  1171. X    update_windows(1);
  1172. X}
  1173. X
  1174. void end_of_buffer_cmd()
  1175. X{
  1176. X    update_windows(NUM_LINES);
  1177. X}
  1178. X
  1179. extern void sys_spawn_cmd()
  1180. X{
  1181. X    int update = 0;
  1182. X    reset_tty();
  1183. X    reset_display();
  1184. X    fflush(stdout);
  1185. X#ifdef VMS
  1186. X    if (LAST_CHAR == '\032') exit(0);
  1187. X    if (do_shell_command()) update = 1; /* scroll region reset by message facility */
  1188. X#else                          
  1189. X    killpg(getpgrp(0),18);
  1190. X    update = 1;
  1191. X#endif
  1192. X    init_tty();
  1193. X    if (update) redraw_display();
  1194. X}
  1195. X
  1196. void redraw_cmd()
  1197. X{
  1198. X    redraw_display();
  1199. X}
  1200. X
  1201. void goto_line_cmd()
  1202. X{
  1203. X    int n = C_LINE;
  1204. X    if (DIGIT_ARG != (int *) NULL) n = *DIGIT_ARG;
  1205. X    else
  1206. X      {
  1207. X          MINI_BUF[0] = 0;
  1208. X          if (!read_from_minibuffer("Line: ", MINI_BUF)) return;
  1209. X          sscanf(MINI_BUF,"%d",&n);
  1210. X          MINI_BUF[0] = 0;
  1211. X      }
  1212. X    update_windows(n);
  1213. X}
  1214. X
  1215. void goto_percent_cmd()
  1216. X{
  1217. X    unsigned char *pos;
  1218. X    int n;
  1219. X    if (DIGIT_ARG != (int *) NULL) n = *DIGIT_ARG;
  1220. X    else
  1221. X      {
  1222. X          MINI_BUF[0] = 0;
  1223. X          if (!read_from_minibuffer("%: ", MINI_BUF)) return;
  1224. X          sscanf(MINI_BUF,"%d",&n);
  1225. X          MINI_BUF[0] = 0;
  1226. X      }
  1227. X    if (n < 0) n = 0; else if (n > 100) n = 100;
  1228. X    pos = BEG + (int) (n * (int) (EOB - BEG)) / 100;
  1229. X    n = what_line(pos);
  1230. X    update_windows(n);
  1231. X}
  1232. X
  1233. void extended_key_cmd()
  1234. X{
  1235. X    if (-1 == do_extended_key()) exit_cmd();
  1236. X}
  1237. X
  1238. void extended_cmd_cmd()
  1239. X{
  1240. X    if (-1 == do_extended_cmd()) exit_cmd();
  1241. X}
  1242. X
  1243. void set_mark_cmd()
  1244. X{
  1245. X    BUF->mark = C_LINE;
  1246. X    message("Mark Set.",0);
  1247. X}
  1248. X
  1249. void goto_mark_cmd()
  1250. X{
  1251. X    int mark = BUF->mark;
  1252. X    BUF->mark = C_LINE;
  1253. X    update_window(mark);
  1254. X    message("Mark Set.",0);
  1255. X}
  1256. X
  1257. void one_window_cmd()
  1258. X{
  1259. X    one_window();
  1260. X}
  1261. X
  1262. void two_window_cmd()
  1263. X{
  1264. X    two_windows();
  1265. X}
  1266. X
  1267. void del_window_cmd()
  1268. X{
  1269. X    delete_window();
  1270. X}
  1271. X
  1272. void other_window_cmd()
  1273. X{
  1274. X    int n = 1;
  1275. X    if (DIGIT_ARG != (int *) NULL) n = *DIGIT_ARG;
  1276. X    other_window(n);
  1277. X}
  1278. X
  1279. X
  1280. void find_next_cmd()
  1281. X{
  1282. X    int col, line, n = 1;
  1283. X    unsigned char *pos;
  1284. X    
  1285. X    if (DIGIT_ARG != NULL) n = *DIGIT_ARG;
  1286. X    line = search(CURS_POS + SEARCH_DIR, n, &col);
  1287. X    if (line < 1) return;
  1288. X    pos = CURS_POS;
  1289. X    if ((line < WIN->beg_line) || (line > WIN->beg_line + WIN->bot - WIN->top))
  1290. X      update_window(line);
  1291. X    CURS_POS = pos;
  1292. X    CURS_ROW = line - C_LINE + 1;
  1293. X    CURS_COL = col;
  1294. X}
  1295. X
  1296. void search_cmd()
  1297. X{
  1298. X    SEARCH_DIR = 1;
  1299. X    if (read_from_minibuffer("Search: ",SEARCH_STR) == -1)
  1300. X      return;
  1301. X    CURS_POS = C_POS;
  1302. X    find_next_cmd();
  1303. X}
  1304. X
  1305. void search_back_cmd()
  1306. X{
  1307. X    SEARCH_DIR = -1;
  1308. X    if (read_from_minibuffer("Search: ",SEARCH_STR) == -1)
  1309. X      return;
  1310. X    find_next_cmd();
  1311. X}
  1312. X
  1313. void help_cmd()
  1314. X{
  1315. X    do_help_command();
  1316. X}
  1317. X
  1318. void find_file_cmd()
  1319. X{
  1320. X    user_get_file();
  1321. X}
  1322. X
  1323. void time_cmd()
  1324. X{
  1325. X    message(get_time(),0);
  1326. X}
  1327. X
  1328. void exit_cmd()
  1329. X{
  1330. X    reset_tty();
  1331. X    reset_display();
  1332. X#ifndef  VMS
  1333. X    fputc('\n',stdout);
  1334. X#endif    
  1335. X    exit(0);
  1336. X}
  1337. X
  1338. void digit_arg_cmd()
  1339. X{
  1340. X    char num[15], ch;
  1341. X    int j = 0;
  1342. X    static int digits;
  1343. X    
  1344. X    num[j++] = LAST_CHAR;
  1345. X    ch = getkey();
  1346. X    while ((ch >= '0') && (ch <= '9'))
  1347. X      {
  1348. X          num[j++] = ch;
  1349. X          ch = getkey();
  1350. X      }
  1351. X    
  1352. X    if (((j == 1) && (LAST_CHAR != '-')) || (j > 1))
  1353. X      {
  1354. X          num[j] = '\0';
  1355. X          sscanf(num,"%d",&digits);
  1356. X          DIGIT_ARG = &digits;
  1357. X      }
  1358. X    LAST_CHAR = ch;
  1359. X    (*root_map[ (int) ch ])();
  1360. X}
  1361. X
  1362. X    
  1363. void toggle_width_cmd()
  1364. X{
  1365. X    if (SCREEN_WIDTH == 80)
  1366. X      {
  1367. X          if (!RESTORE_WIDTH_TO) RESTORE_WIDTH_TO = 80;
  1368. X          set_width(132, 1);
  1369. X      }          
  1370. X    else if (SCREEN_WIDTH == 132)
  1371. X      {
  1372. X          if (!RESTORE_WIDTH_TO) RESTORE_WIDTH_TO = 132;
  1373. X          set_width(80, 1);
  1374. X      }          
  1375. X}
  1376. X
  1377. void edt_forward_cmd()
  1378. X{
  1379. X    EDT_DIRECTION = 1;
  1380. X}
  1381. X
  1382. void edt_back_cmd()
  1383. X{
  1384. X    EDT_DIRECTION = 0;
  1385. X}
  1386. X
  1387. void edt_page_cmd()
  1388. X{
  1389. X    if (EDT_DIRECTION == 0)
  1390. X    {
  1391. X        page_up_cmd();
  1392. X    }
  1393. X    else
  1394. X    {
  1395. X        page_down_cmd();
  1396. X    }
  1397. X}
  1398. X
  1399. void edt_line_cmd()
  1400. X{
  1401. X    if (EDT_DIRECTION == 0)
  1402. X    {
  1403. X        previous_line_cmd();
  1404. X    }
  1405. X    else
  1406. X    {
  1407. X        next_line_cmd();
  1408. X    }
  1409. X}
  1410. X
  1411. void edt_find_cmd()
  1412. X{
  1413. X    if (EDT_DIRECTION == 0)
  1414. X    {
  1415. X        search_back_cmd();
  1416. X    }
  1417. X    else
  1418. X    {
  1419. X        search_cmd();
  1420. X    }
  1421. X}
  1422. X
  1423. void edt_find_next_cmd()
  1424. X{
  1425. X    if (EDT_DIRECTION == 0)
  1426. X    {
  1427. X        SEARCH_DIR = -1;
  1428. X    }
  1429. X    else
  1430. X    {
  1431. X        SEARCH_DIR = 1;
  1432. X    }
  1433. X    find_next_cmd();
  1434. X}
  1435. END_OF_FILE
  1436. if test 32690 -ne `wc -c <'keym.c'`; then
  1437.     echo shar: \"'keym.c'\" unpacked with wrong size!
  1438. fi
  1439. # end of 'keym.c'
  1440. fi
  1441. if test -f 'most.1' -a "${1}" != "-c" ; then 
  1442.   echo shar: Will not clobber existing file \"'most.1'\"
  1443. else
  1444. echo shar: Extracting \"'most.1'\" \(12801 characters\)
  1445. sed "s/^X//" >'most.1' <<'END_OF_FILE'
  1446. X.\"--------------------------------------------------------------------
  1447. X.\" UX - UNIX macro, to append \(rg to the first usage
  1448. X.\"--------------------------------------------------------------------
  1449. X.de UX
  1450. X.ie \\n(UX \s-1UNIX\s0\\$1
  1451. X.el      \{\s-1UNIX\s0\\$1\*(Rg
  1452. X.          nr UX 1
  1453. X.\}
  1454. X..
  1455. X.\"--------------------------------------------------------------------
  1456. X.\" Ds - start indented display
  1457. X.\" De - end indented display
  1458. X.\"--------------------------------------------------------------------
  1459. X.de Ds
  1460. X.nf
  1461. X'in +0.5i
  1462. X..
  1463. X.de De
  1464. X'in
  1465. X.fi
  1466. X..
  1467. X.TH MOST 1 "1 June 1992"
  1468. X.SH NAME
  1469. most \- browse or page through a text file
  1470. X.SH SYNOPSIS
  1471. X.B most
  1472. X.RB [ \-bstvw ]
  1473. X.RB [ +\fIlineno\fB ]
  1474. X.RB [ +c ]
  1475. X.RB [ +d ]
  1476. X.RB [ +/\fIstring\fB ]
  1477. X.RI [ filename ...]
  1478. X.SH DESCRIPTION
  1479. X.I most
  1480. is a paging program that displays,
  1481. one windowful at a time,
  1482. the contents of a file on a
  1483. X.RI vt xxx
  1484. compatable terminal.
  1485. It pauses after each windowful and prints on the window status line
  1486. the screen the file name, current line number,
  1487. and the percentage of the file so far displayed.
  1488. X.PP
  1489. Unlike other paging programs,
  1490. X.I most
  1491. is capable of displaying an arbitrary number of windows
  1492. as long as each window occupies at least two screen lines.
  1493. XEach window may contain the same file or a different file.
  1494. In addition, each window has its own mode.
  1495. XFor example, one window may display a file with its lines wrapped while
  1496. another may be truncating the lines.
  1497. Windows may be `locked'
  1498. together in the sense that if one of the locked windows scrolls,
  1499. all locked windows will scroll.
  1500. X.I most
  1501. is also capable of ignoring lines
  1502. that are indented beyond a user specified value.
  1503. This is useful when viewing computer programs to pick out
  1504. gross features of the code.
  1505. See the
  1506. X.RB ` :o '
  1507. command for a description of this feature.
  1508. X.PP
  1509. In addition to displaying ordinary text files,
  1510. X.I most
  1511. can also display binary files as well as files with arbitrary ascii
  1512. characters.
  1513. When a file is read into a buffer,
  1514. X.I most
  1515. examines the first 32 bytes of
  1516. the file to determine if the file is a binary file and then switches
  1517. to the appropriate mode.
  1518. However, this feature may be disabled with the
  1519. X.B \-k
  1520. option.
  1521. See the description of the
  1522. X.BR \-b ,
  1523. X.BR \-k ,
  1524. X.BR \-v ,
  1525. and
  1526. X.B \-t
  1527. options for further details.
  1528. X.PP
  1529. Text files may contain combinations of underscore and backspace
  1530. characters causing a printer to underline or overstrike.
  1531. When
  1532. X.I most
  1533. recognizes this,
  1534. it inserts the appropriate escape sequences to
  1535. achieve these the desired effect on
  1536. X.RI vt xxx
  1537. compatable terminals.
  1538. In addition,
  1539. some files cause the printer to overstrike some characters
  1540. by embedding carriage return characters in the middle of a line.
  1541. When this occurs,
  1542. X.I most
  1543. displays the overstruck character with a bold
  1544. attribute.
  1545. This feature facilitates the reading of
  1546. X.UX
  1547. man pages or a document produced by
  1548. X.IR runoff .
  1549. In particular,
  1550. viewing this document with
  1551. X.I most
  1552. should illustrate this behavior provided that the
  1553. underline characters have not been stripped.
  1554. This may be turned off with the
  1555. X.B \-v
  1556. option.
  1557. X.PP
  1558. By default, lines with more characters than the terminal width are
  1559. not wrapped but are instead truncated.
  1560. When truncation occurs, this
  1561. is indicated by a `$' in the far right column of the terminal
  1562. screen.
  1563. The RIGHT and LEFT arrow keys may be used to view lines
  1564. which extend past the margins of the screen.
  1565. The
  1566. X.B \-w
  1567. option may be used to override this feature.
  1568. When a window is wrapped,
  1569. the character `\e' will appear at the right edge of the window.
  1570. X.PP
  1571. Commands are listed below.
  1572. X.SH OPTIONS
  1573. X.TP
  1574. X.B \-b
  1575. Binary mode.
  1576. Use this switch when you want to view files
  1577. containing 8 bit characters.
  1578. X.I most
  1579. will display the file 16 bytes per line in hexidecimal notation.
  1580. A typical line looks like:
  1581. X.IP
  1582. X.Ds
  1583. X01000000 40001575 9C23A020 4000168D     ....@..u.#. @...
  1584. X.De
  1585. X.IP
  1586. When used with the
  1587. X.B \-v
  1588. option, the same line looks like:
  1589. X.IP
  1590. X.Ds
  1591. X^A^@^@^@  @^@^U u 9C #A0    @^@^V8D     ....@..u.#. @...
  1592. X.De
  1593. X.TP
  1594. X.B \-k
  1595. X`Kanji' option.
  1596. Ordinarily,
  1597. X.I most
  1598. will go into binary mode if the file consists of non-ascii characters.
  1599. Sometimes this feature is not desirable since some
  1600. terminals have a special interpretation for eight bit
  1601. characters.
  1602. The
  1603. X.B \-k
  1604. option turns off the automatic sensing.
  1605. X.TP
  1606. X.B \-s
  1607. Squeeze.
  1608. Replace multiple blank lines with a single blank line.
  1609. X.TP
  1610. X.B \-v
  1611. Display control characters as in `^A' for control A.
  1612. Normally
  1613. X.I most
  1614. does not interpret control characters.
  1615. X.TP
  1616. X.B \-t
  1617. Display tabs as `^I'.
  1618. This option is meaningful only when used with the
  1619. X.B \-v
  1620. option.
  1621. X.BI + lineno
  1622. Start up at
  1623. X.IR lineno .
  1624. X.TP
  1625. X.B +c
  1626. Make search case sensitive.
  1627. By default, they are not.
  1628. X.TP
  1629. X.B +d
  1630. This switch should only be used if you want the option to
  1631. delete a file while viewing it.
  1632. This makes it easier to
  1633. clean unwanted files out of a directory.
  1634. The file is
  1635. deleted with the interactive key sequence
  1636. X.RB ` :D '
  1637. and then confirming with
  1638. X.RB ` y '.
  1639. X.TP
  1640. X.BI +/ string
  1641. Start up at the line containing the first occurrence of
  1642. X.IR string .
  1643. X.SH "COMMAND USAGE"
  1644. The commands take effect immediately; it is not necessary to type a
  1645. carriage return.
  1646. X.PP
  1647. In the following commands,
  1648. X.I i
  1649. is a numerical argument
  1650. X(1 by default).
  1651. X.TP
  1652. X.BR SPACE ", " CTRL-D ", " NEXT_SCREEN
  1653. Display another windowful, or jump
  1654. X.I i
  1655. windowfuls if
  1656. X.I i
  1657. is specified.
  1658. X.TP
  1659. X\fBRETURN\fR, \fBDOWN_ARROW\fR, \fBV\fR, \fBCTRL-N\fR
  1660. Display another line, or
  1661. X.I i
  1662. more lines, if specified.
  1663. X.TP
  1664. X.BR UP_ARROW ", " ^ ", " CTRL-P
  1665. Display previous line, or
  1666. X.I i
  1667. previous lines, if specified.
  1668. X.TP
  1669. X.BR T ", " ESCAPE <
  1670. Move to top of buffer.
  1671. X.TP
  1672. X.BR B ", " ESCAPE >
  1673. Move to bottom of buffer.
  1674. X.TP
  1675. X.BR RIGHT_ARROW ", " TAB ", " >
  1676. Scroll window left
  1677. X.RI 60 i
  1678. columns to view lines that are beyond the right margin of the window.
  1679. X.TP
  1680. X.BR LEFT_ARROW ", " CTRL-B ", " <
  1681. Scroll window right
  1682. X.RI 60 i
  1683. columns to view lines that are beyond the left margin of the window.
  1684. X.TP
  1685. X\fBU\fR, \fBCTRL-U\fR, \fBDELETE\fR, \fBPREV_SCREEN\fR
  1686. Skip back
  1687. X.I i
  1688. windowfuls and then print a windowful.
  1689. X.TP
  1690. X.BR R ", " CTRL-R
  1691. Redraw the window.
  1692. X.TP
  1693. X.BR J ", " G
  1694. If
  1695. X.I i
  1696. is not specified, then prompt for a line number then jump to that line
  1697. otherwise just jump to line
  1698. X.IR i .
  1699. X.TP
  1700. X.B %
  1701. If
  1702. X.I i
  1703. is not specified, then prompt for a
  1704. percent number then jump to that percent of the
  1705. file otherwise just jump to
  1706. X.I i
  1707. percent of the file.
  1708. X.TP
  1709. X.BR W ", " w
  1710. If the current screen width is 80, make it 132 and vice-versa.
  1711. XFor other values, this command is ignored.
  1712. X.TP
  1713. X\fBQ\fR, \fBCTRL-X CTRL-C\fR, \fBCTRL-K E\fR
  1714. XExit from
  1715. X.IR most .
  1716. On VMS, ^Z also exits.
  1717. X.TP
  1718. X.BR h ", " CTRL-H ", " HELP ", " PF2
  1719. Help.
  1720. Give a description of all the
  1721. X.I most
  1722. commands.
  1723. The
  1724. X.I most
  1725. environment variable
  1726. X.B MOST_HELP
  1727. must be set for this to be meaningful.
  1728. X.TP
  1729. X\fBf\fR, \fB/\fR, \fBCTRL-F\fR, \fBFIND\fR, \fBGOLD PF3\fr
  1730. Prompt for a string and search forward from the
  1731. current line for
  1732. X.IR i th
  1733. distinct line containing the string.
  1734. X.B CTRL-G
  1735. aborts.
  1736. X.TP
  1737. X.B ?
  1738. Prompt for a string and search backward for the
  1739. X.IR i th
  1740. distinct line containing the string.
  1741. X.B CTRL-G
  1742. aborts.
  1743. X.TP
  1744. X.B n
  1745. Search for the next
  1746. X.I i
  1747. lines containing an occurrence of the last search string in the
  1748. direction of the previous search.
  1749. X.\"-------
  1750. X.\" The '@' causes problems when included in a paragraph tag
  1751. X.\" in my system's -man macro set, so jump though some hoops to
  1752. X.\" avoid doing this.
  1753. X.\"-------
  1754. X.PP
  1755. X\fBm\fR, \fBSELECT\fR, \fBCTRL-@\fR, \fBCTRL-K M\fR, \fBPERIOD\fR
  1756. X.PD 0
  1757. X.IP
  1758. X.PD
  1759. Set a mark on the current line for later reference.
  1760. X.TP
  1761. X.BR "INSERT_HERE, CTRL-X CTRL-X, COMMA, CTRL-K RETURN, GOLD PERIOD"
  1762. Set a mark on the current line but return to previous mark.
  1763. This allows the user to toggle back and forth between two positions
  1764. in the file.
  1765. X.TP
  1766. X.BR l ", " L
  1767. Toggle locking for this window.
  1768. The window is locked if there is a `*' at the left edge
  1769. of the status line.
  1770. Windows locked together, scroll together.
  1771. X.TP
  1772. X.BR "CTRL-X 2" ", " "CTRL-W 2" ", " "GOLD X"
  1773. Split this window in half.
  1774. X.TP
  1775. X.BR "CTRL-X o" ", " "CTRL-W o" ", " o ", " GOLD UP ", " GOLD DOWN 
  1776. Move to other window.
  1777. X.TP
  1778. X.BR "CTRL-X 0" ", " "CTRL-W 0" ", " "GOLD V"
  1779. Delete this window.
  1780. X.TP
  1781. X.BR "CTRL-X 1" ", " "CTRL-W 1" ", " "GOLD O"
  1782. Delete all other windows, leaving only one window.
  1783. X.TP
  1784. X.BR E ", " e
  1785. XEdit this file.
  1786. This does not spawn an editor, rather
  1787. X.I most
  1788. uses callable EDT and TPU routines to perform the editing task.
  1789. In addition,
  1790. X.I most
  1791. can attach to a kept editor.
  1792. See the above discussion of the environment variable
  1793. X.BR MOST_EDITOR .
  1794. X.TP
  1795. X.BR $ ", " "ESC $"
  1796. This is system dependent.
  1797. On VMS, this causes
  1798. X.I most
  1799. to spawn a subprocess.
  1800. When the user exits the process,
  1801. X.I most
  1802. is resumed.
  1803. On
  1804. X.UX
  1805. systems,
  1806. X.I most
  1807. simply suspends itself.
  1808. X.TP
  1809. X.B :n
  1810. Skip to the next filename given in the command line.
  1811. Use the arrow keys to scroll forward or backward
  1812. through the file list.
  1813. X.RB ` Q '
  1814. quits
  1815. X.I most
  1816. and any other key selects the given file.
  1817. X.TP
  1818. X.B :c
  1819. Toggle case sensitive search.
  1820. X.TP
  1821. X.B :D
  1822. Delete current file.
  1823. This command is only meaningful with the
  1824. X.B +d
  1825. switch.
  1826. X.TP
  1827. X.BR :o ", " :O
  1828. Toggle various options.
  1829. With this key sequence,
  1830. X.I most
  1831. displays a prompt asking the user to hit
  1832. one of:
  1833. X.BR bdtvw .
  1834. The
  1835. X.RB ` b ',
  1836. X.RB ` t ',
  1837. X.RB ` v ',
  1838. and
  1839. X.RB ` w '
  1840. options have the same meaning as the command
  1841. line switches.
  1842. XFor example, the
  1843. X.RB ` w '
  1844. option will toggle wrapping on and off for the current window.
  1845. X.IP
  1846. The
  1847. X.RB ` d '
  1848. option must be used with a prefix integer
  1849. X.IR i .
  1850. All lines indented beyond
  1851. X.I i
  1852. columns will not be displayed.
  1853. XFor example, consider the fragment:
  1854. X.IP
  1855. X.Ds
  1856. X.ne 11
  1857. int main(int argc, char **argv)
  1858. X{
  1859. X    int i;
  1860. X
  1861. X    for (i = 0; i < argc, i++)
  1862. X    {
  1863. X        fprintf(stdout,"%i: %s\en",i,argv[i]);
  1864. X    }
  1865. X    return 0;
  1866. X}
  1867. X.De
  1868. X.IP
  1869. The key sequence
  1870. X.RB ` 1:od '
  1871. will cause
  1872. X.I most
  1873. to display the file ignoring all lines indented beyond the first column.
  1874. So for the example above,
  1875. X.I most
  1876. would display:
  1877. X.IP
  1878. X.Ds
  1879. X.ne 2
  1880. int main(int argc, char **argv)...
  1881. X}
  1882. X.De
  1883. X.IP
  1884. where the `...' indicates lines follow are not displayed.
  1885. X.SH HINTS
  1886. X.B CTRL-G
  1887. aborts the commands requiring the user to type something
  1888. in at a prompt.
  1889. The backquote key has a special meaning here.
  1890. It is used to quote certain characters.
  1891. This is useful when search for
  1892. the occurrence of a string with a control character or a string at
  1893. the beginning of a line.
  1894. In the latter case, to find the occurrence
  1895. of `The' at the beginning of a line, enter
  1896. X.B `^JThe
  1897. where
  1898. X.B `
  1899. quotes the
  1900. X.BR CTRL-J .
  1901. X.SH ENVIRONMENT
  1902. X.I most
  1903. uses the following environment variables:
  1904. X.TP
  1905. X.B MOST_SWITCHES
  1906. This variable sets commonly used switches.
  1907. XFor example,
  1908. some people prefer to use
  1909. X.I most
  1910. with the
  1911. X.B \-s
  1912. option so that excess blank lines are not displayed.
  1913. On VMS this is normally done done in the login.com through the line:
  1914. X.IP
  1915. X.Ds
  1916. X$ define MOST_SWITCHES "-s"
  1917. X.De
  1918. X.TP
  1919. X.BR MOST_EDITOR " (VMS only)"
  1920. Set this logical to one of three values: EDT, TPU, or EMACS.
  1921. The default is EDT.
  1922. X.I most
  1923. does not spawn an editor.
  1924. Rather, it uses callable EDT and TPU to perform the editing task.
  1925. Since VMS does not support callable EMACS,
  1926. X.I most
  1927. will attempt to attach to a kept EMACS.
  1928. XFor this case,
  1929. X.I most
  1930. looks for the logical name EMACS_PID and attaches to the process with
  1931. that pid.
  1932. It then defines the logicals EMACS_FILE_NAME and
  1933. XEMACS_FILE_LINE which EMACS can check upon attaching to it.
  1934. X.TP
  1935. X.B MOST_HELP
  1936. This variable must be setup to point to the
  1937. X.I most
  1938. helpfile.
  1939. Without this
  1940. X.I most
  1941. will not be able to provide online help.
  1942. However, this behavior may be changed at compile time.
  1943. See the Makefile for more information.
  1944. X.SH BUGS
  1945. Almost all of the known bugs or limitations of
  1946. X.I most
  1947. are due to a desire to read and interpret control characters in files.
  1948. One problem concerns the use of backspace characters to underscore or
  1949. overstrike other characters.
  1950. X.I most
  1951. makes an attempt to use terminal
  1952. escape sequences to simulate this behavior.
  1953. One side effect is the
  1954. one does not always get what one expects when scrolling right and
  1955. left through a file.
  1956. When in doubt, use the
  1957. X.B \-v
  1958. and
  1959. X.B \-b
  1960. options of
  1961. X.IR most .
  1962. X.PP
  1963. String may not work properly with binary files.
  1964. X.PP
  1965. At this time,
  1966. X.I most
  1967. only works well with terminals understanding
  1968. vt100 escape sequences.
  1969. X.I most
  1970. does not seem to have any problem with
  1971. X.IR xterm .
  1972. X.PP
  1973. X.IR malloc (3)
  1974. failures are not checked.
  1975. X.I most
  1976. may crash if there is not
  1977. enough room to hold the file.
  1978. X.SH AUTHOR
  1979. John E. Davis
  1980. X.br
  1981. The Ohio State University
  1982. X.br
  1983. Department of Physics
  1984. X.br
  1985. davis@pacific.mps.ohio-state.edu
  1986. X.SH ACKNOWLEDGEMENTS
  1987. I would like to thank the users of
  1988. X.I most
  1989. for valuable comments and criticisms.
  1990. I would especially like to thank those individuals
  1991. who have contributed code to
  1992. X.IR most :
  1993. X.PP
  1994. Mats Akerberg, Henk D. Davids, Rex O. Livingston, and Mark Pizzolato
  1995. X.PP
  1996. I would also like to thank Shinichi Hama for his valuable criticisms of
  1997. X.IR most .
  1998. X.PP
  1999. Thanks to David W. Sanderson (dws@cs.wisc.edu) for adapting the
  2000. documentation to nroff man page source format.
  2001. END_OF_FILE
  2002. if test 12801 -ne `wc -c <'most.1'`; then
  2003.     echo shar: \"'most.1'\" unpacked with wrong size!
  2004. fi
  2005. # end of 'most.1'
  2006. fi
  2007. if test -f 'sysdep.c' -a "${1}" != "-c" ; then 
  2008.   echo shar: Will not clobber existing file \"'sysdep.c'\"
  2009. else
  2010. echo shar: Extracting \"'sysdep.c'\" \(11684 characters\)
  2011. sed "s/^X//" >'sysdep.c' <<'END_OF_FILE'
  2012. X/*
  2013. X * HISTORY
  2014. X * {1}    19-Mar-91  Henk D. Davids <hdavids@mswe.dnet.ms.philips.nl>
  2015. X *     History started. Added default input file name so you do not
  2016. X *    have to specify name or type if you want it to be *.
  2017. X *     Changes indicated by "-hdd" in comment.
  2018. X * 
  2019. X *  2.  4/4/91  John E. Davis
  2020. X *      I added code to read the teminal size for unix systems-- at least it
  2021. X *      works on a sun4 (BSD ?).  In addition I have also recently added file
  2022. X *      deletion code for both unix and vms.
  2023. X */
  2024. X#include "sysdep.h"
  2025. X
  2026. X
  2027. X/* 
  2028. X *  
  2029. X *  
  2030. X *                          SHELL COMMANDS
  2031. X *  
  2032. X */
  2033. X  
  2034. X#ifdef VMS
  2035. X
  2036. X/* these two from emacs source */  
  2037. void define_logical_name (char *varname, char *string)
  2038. X{
  2039. X    struct dsc$descriptor_s strdsc =
  2040. X      {strlen (string), DSC$K_DTYPE_T, DSC$K_CLASS_S, string};
  2041. X    struct dsc$descriptor_s envdsc =
  2042. X      {strlen (varname), DSC$K_DTYPE_T, DSC$K_CLASS_S, varname};
  2043. X    struct dsc$descriptor_s lnmdsc =
  2044. X      {7, DSC$K_DTYPE_T, DSC$K_CLASS_S, "LNM$JOB"};
  2045. X
  2046. X    LIB$SET_LOGICAL (&envdsc, &strdsc, &lnmdsc, 0, 0);
  2047. X}
  2048. X
  2049. void delete_logical_name (char *varname)
  2050. X{
  2051. X    struct dsc$descriptor_s envdsc =
  2052. X      {strlen (varname), DSC$K_DTYPE_T, DSC$K_CLASS_S, varname};
  2053. X    struct dsc$descriptor_s lnmdsc =
  2054. X      {7, DSC$K_DTYPE_T, DSC$K_CLASS_S, "LNM$JOB"};
  2055. X    
  2056. X    LIB$DELETE_LOGICAL (&envdsc, &lnmdsc);
  2057. X}
  2058. X
  2059. X
  2060. int do_emacs_command()
  2061. X{
  2062. X    unsigned long pid;
  2063. X    char *pidstr;
  2064. X    
  2065. X    if((pidstr = getenv("EMACS_PID")) != NULL)
  2066. X      {
  2067. X      (void) sscanf(pidstr,"%X",&pid);
  2068. X      if (lib$attach(&pid) == SS$_NORMAL) /* we attach to emacs */
  2069. X            return(1);
  2070. X          else
  2071. X            return(0);
  2072. X          /*         printf("Can't attach to pid %X\n",pid); */
  2073. X      }
  2074. X    else return(0);
  2075. X}
  2076. X
  2077. unsigned long SHELL_PID = 0;  
  2078. X
  2079. X/* returns 0 on success */
  2080. int do_shell_command()
  2081. X{
  2082. X    /* here we try to attach to the parent otherwise just spawn a new one */
  2083. X    unsigned long parent_pid;
  2084. X    unsigned long status = 0;
  2085. X    char str[80];
  2086. X    
  2087. X    
  2088. X    parent_pid = getppid();
  2089. X    
  2090. X    if (parent_pid && parent_pid != 0xffffffff)  
  2091. X      /* we attach to parent */
  2092. X      status = lib$attach(&parent_pid);
  2093. X
  2094. X    else if (SHELL_PID && SHELL_PID != 0xffffffff)
  2095. X      /* try to attach to previous shell */
  2096. X      status = lib$attach (&SHELL_PID);
  2097. X      
  2098. X    if (status != SS$_NORMAL)        /* others fail so spawn a new shell */
  2099. X      {
  2100. X          status = 0;
  2101. X      fputs("Spawning Subprocess...",stdout);
  2102. X          fflush(stdout);
  2103. X      lib$spawn(0,0,0,0,0,&SHELL_PID,&status);
  2104. X          /* if we attach back, status may come back unchanged */
  2105. X          if ((status != 0) && (status != SS$_NORMAL))
  2106. X            {
  2107. X                sprintf(str,"Unable to spawn subprocess. Error = %X", status);
  2108. X                message(str,1);
  2109. X                return(0);
  2110. X            }
  2111. X      }
  2112. X    return(1);
  2113. X}
  2114. X
  2115. X
  2116. X#endif /* VMS */
  2117. X
  2118. X/* 
  2119. X *                            FILE IO
  2120. X *  
  2121. X */
  2122. X
  2123. X#ifdef VMS
  2124. int expand_file_name(char *file,char *expanded_file)
  2125. X{
  2126. X    unsigned long status;
  2127. X    static int context = 0;
  2128. X    static char inputname[255] = "";
  2129. X    $DESCRIPTOR(file_desc,inputname);
  2130. X    $DESCRIPTOR(default_dsc,"SYS$DISK:[]*.*;");
  2131. X    static struct dsc$descriptor_s  result = 
  2132. X        {0, DSC$K_DTYPE_T, DSC$K_CLASS_D, NULL};
  2133. X
  2134. X    if (strcmp(inputname, file))
  2135. X      {
  2136. X      if (context)
  2137. X        {
  2138. X        lib$find_file_end(&context);
  2139. X        }
  2140. X      context = 0;
  2141. X      strcpy(inputname, file);
  2142. X      file_desc.dsc$w_length = strlen(inputname);
  2143. X      }
  2144. X    
  2145. X    if (RMS$_NORMAL == lib$find_file(&file_desc,&result,&context,
  2146. X                            &default_dsc,0,0,&0))
  2147. X      {
  2148. X      memcpy(expanded_file, result.dsc$a_pointer, result.dsc$w_length);
  2149. X      expanded_file[result.dsc$w_length] = '\0';
  2150. X          return (1);
  2151. X      }
  2152. X    else
  2153. X      {
  2154. X          expanded_file[0] = '\0';       /* so file comes back as zero width */
  2155. X          return(0);
  2156. X      }
  2157. X}
  2158. X#endif /* VMS */
  2159. X
  2160. X/* 
  2161. X *  
  2162. X *  
  2163. X *         Terminal IO
  2164. X *  
  2165. X */
  2166. X
  2167. X#ifdef VMS
  2168. X/*
  2169. X *      Exit Handler Control Block
  2170. X */
  2171. static struct argument_block
  2172. X    {
  2173. X    int forward_link;
  2174. X    int (*exit_routine)();
  2175. X    int arg_count;
  2176. X    int *status_address;
  2177. X    int exit_status;
  2178. X    } exit_block
  2179. X      = {
  2180. X        0,
  2181. X        NULL,
  2182. X        1,
  2183. X        &exit_block.exit_status,
  2184. X        0
  2185. X        };
  2186. X#endif
  2187. void init_tty()
  2188. X{
  2189. X#ifdef VMS
  2190. X    $DESCRIPTOR ( Term, "SYS$ERROR");
  2191. X    if (sys$assign ( &Term, &TTY_CHANNEL_GLOBAL, 0, 0 )
  2192. X        != SS$_NORMAL)
  2193. X      {
  2194. X          fprintf(stderr,"Unable to assign input channel\n");
  2195. X          exit(0);
  2196. X      }
  2197. X    if (NULL == exit_block.exit_routine)
  2198. X    {
  2199. X    void reset_tty();
  2200. X
  2201. X    exit_block.exit_routine = reset_tty;
  2202. X    SYS$DCLEXH(&exit_block);
  2203. X    }
  2204. X#else    
  2205. X#ifdef BSD
  2206. X    struct sgttyb  newtty;
  2207. X    struct tchars tc;
  2208. X    struct ltchars lc;
  2209. X
  2210. X    ioctl(TTY_DESCR, TIOCGLTC,&OLDTTY_LC);
  2211. X    ioctl(TTY_DESCR, TIOCGETC,&OLDTTY_TC);
  2212. X    ioctl(TTY_DESCR, TIOCGETP, &OLDTTY);
  2213. X    newtty = OLDTTY;
  2214. X    newtty.sg_flags |= CBREAK;
  2215. X    newtty.sg_flags &= ~(ECHO | XTABS);
  2216. X    newtty.sg_erase = 0;
  2217. X    newtty.sg_kill = 0;
  2218. X    tc.t_intrc = 0;
  2219. X    tc.t_quitc = 0;
  2220. X    tc.t_eofc = 0;
  2221. X    tc.t_brkc = 0;
  2222. X    lc.t_suspc = 0;
  2223. X    lc.t_dsuspc = 0;
  2224. X    ioctl(TTY_DESCR, TIOCSETP, &newtty);
  2225. X    ioctl(TTY_DESCR, TIOCSLTC,&lc);
  2226. X    ioctl(TTY_DESCR, TIOCSETC,&tc);
  2227. X#else /* other unix */    
  2228. X    struct termio newtty;
  2229. X      
  2230. X    ioctl(TTY_DESCR, TCGETA, &OLDTTY);
  2231. X    ioctl(TTY_DESCR, TCGETA, &newtty);
  2232. X    newtty.c_iflag &= ~(ECHO);  
  2233. X    newtty.c_iflag &= ~(INLCR);  
  2234. X    newtty.c_iflag &= ~(ICRNL);  
  2235. X    newtty.c_lflag = 00000000; 
  2236. X    newtty.c_cc[VMIN] = 1; 
  2237. X    newtty.c_cc[VTIME] = 0;
  2238. X    newtty.c_cc[VEOF] = 1;          
  2239. X    ioctl(TTY_DESCR, TCSETA, &newtty);
  2240. X
  2241. X#endif  /* other unix */
  2242. X#endif
  2243. X    fputs("\033=", stdout);  /* Enable the Application Keypad */
  2244. X}
  2245. X
  2246. sys_flush(int fd)
  2247. X{
  2248. X#ifdef BSD
  2249. X    ioctl(fd, TIOCFLUSH, (char *) NULL);
  2250. X#else
  2251. X#ifndef VMS    
  2252. X    ioctl(fd, TCFLSH, (char *) NULL);
  2253. X#endif    
  2254. X#endif    
  2255. X}
  2256. X
  2257. void reset_tty()
  2258. X{
  2259. X    fputs("\033=", stdout);  /* Enable the Numeric Keypad */
  2260. X#ifndef VMS
  2261. X#ifdef BSD
  2262. X    ioctl(TTY_DESCR, TIOCSETP, &OLDTTY);
  2263. X    ioctl(TTY_DESCR, TIOCSLTC, &OLDTTY_LC);
  2264. X    ioctl(TTY_DESCR, TIOCSETC, &OLDTTY_TC);
  2265. X#else        
  2266. X        ioctl(TTY_DESCR, TCSETA, &OLDTTY);
  2267. X#endif /* BSD */
  2268. X#endif /* not vms*/
  2269. X}
  2270. X
  2271. int INPUT_BUFFER_LEN = 0;
  2272. char INPUT_BUFFER[80];
  2273. X
  2274. char sys_getkey()
  2275. X{
  2276. X    char c;
  2277. X    
  2278. X#ifndef VMS
  2279. X    if (read(TTY_DESCR, &c, 1) < 0)
  2280. X      {
  2281. X          fprintf(stderr,"getkey():  read failed.\n");
  2282. X          reset_tty();
  2283. X          exit(0);
  2284. X      }
  2285. X    
  2286. X#else
  2287. X    /* VMS */
  2288. X    /* see Guide to Programming VAX/VMS */
  2289. X    int status;
  2290. X    static int trmmsk [2] = { 0, 0 };
  2291. X    short iosb [4];
  2292. X    
  2293. X    status = sys$qiow ( 0, TTY_CHANNEL_GLOBAL,
  2294. X                       IO$_READVBLK + IO$M_NOECHO | IO$_TTYREADALL,
  2295. X                       iosb, 0, 0,
  2296. X                       &c, 1, 0, trmmsk, 0, 0 );
  2297. X
  2298. X#endif  /* VMS */
  2299. X    
  2300. X    return(c); 
  2301. X}
  2302. X
  2303. char getkey()
  2304. X{
  2305. X    int i;
  2306. X    char ch;
  2307. X    if (!INPUT_BUFFER_LEN) return(sys_getkey());
  2308. X    ch = INPUT_BUFFER[0];
  2309. X    INPUT_BUFFER_LEN--;
  2310. X    for (i = 0; i < INPUT_BUFFER_LEN; i++)
  2311. X      {
  2312. X          INPUT_BUFFER[i] = INPUT_BUFFER[i + 1];
  2313. X      }
  2314. X    return(ch);
  2315. X}
  2316. X
  2317. void ungetkey(char ch)
  2318. X{
  2319. X    int i;
  2320. X    for (i = 0; i < INPUT_BUFFER_LEN; i++)
  2321. X      {
  2322. X          INPUT_BUFFER[i+1] = INPUT_BUFFER[i];
  2323. X      }
  2324. X    INPUT_BUFFER[0] = ch;
  2325. X    INPUT_BUFFER_LEN++;
  2326. X}
  2327. X
  2328. X
  2329. X/* 
  2330. X *  
  2331. X *      Misc Termial stuff  
  2332. X *  
  2333. X *  
  2334. X */
  2335. X
  2336. X
  2337. X/*  This is to get the size of the terminal  */
  2338. void get_term_dimensions(int *cols, int *rows)
  2339. X{
  2340. X#ifdef VMS
  2341. X    int status;
  2342. X    iosb iostatus;
  2343. X    $DESCRIPTOR(devnam, "SYS$ERROR");
  2344. X    struct
  2345. X    {
  2346. X    short row_buflen;
  2347. X    short row_itmcod;
  2348. X    int *row_bufadr;
  2349. X    short *row_retlen;
  2350. X    short col_buflen;
  2351. X    short col_itmcod;
  2352. X    int *col_bufadr;
  2353. X    short *col_retlen;
  2354. X    int listend;
  2355. X    } itmlst =
  2356. X    {
  2357. X    sizeof(*rows), DVI$_TT_PAGE, rows, 0,
  2358. X    sizeof(*cols), DVI$_DEVBUFSIZ, cols, 0,
  2359. X    0
  2360. X    };
  2361. X    
  2362. X    /* Get current terminal characteristics */
  2363. X    status = sys$getdviw(0,           /* Wait on event flag zero  */
  2364. X                         0,           /* Channel to input terminal  */
  2365. X                         &devnam,     /* device name */
  2366. X             &itmlst,      /* Item descriptor List */
  2367. X                         &iostatus,   /* Status after operation */
  2368. X                         0, 0,        /* No AST service   */
  2369. X                         0);          /* nullarg */
  2370. X    if (status&1)
  2371. X    status = iostatus.i_cond;
  2372. X    /* Jump out if bad status */
  2373. X    if ((status & 1) == 0)
  2374. X      exit(status);
  2375. X#else    /* this may need work on other unix-- works for sun4 */
  2376. X    struct winsize wind_struct;
  2377. X      
  2378. X    ioctl(2,TIOCGWINSZ,&wind_struct);
  2379. X    *cols = (int) wind_struct.ws_col;
  2380. X    *rows = (int) wind_struct.ws_row;
  2381. X    
  2382. X#endif /* VMS */
  2383. X}
  2384. X
  2385. X/* returns 0 on failure, 1 on sucess */
  2386. int sys_delete_file(char *filename)
  2387. X{
  2388. X#ifdef VMS
  2389. X    return (1 + delete(filename));   /* 0: sucess; -1 failure */
  2390. X#else  /* unix not ready yet */
  2391. X    return(1 + unlink(filename));
  2392. X#endif
  2393. X}
  2394. X
  2395. X
  2396. X/* This routine converts unix type names to vms names */
  2397. X#ifdef VMS
  2398. int locate(char ch, char *string)
  2399. X{
  2400. X    int i;
  2401. X    char c;
  2402. X
  2403. X    i = 0;
  2404. X    while (c = string[i++], (c != ch) && (c != '\0'));
  2405. X    if (c == ch) return(i); else return (0);
  2406. X}
  2407. X
  2408. char *unix2vms(char *file)
  2409. X{
  2410. X    int i,device,j,first,last;
  2411. X    static char vms_name[80];
  2412. X    char ch;
  2413. X
  2414. X    if (locate('[',file)) return(file); /* vms_name syntax */
  2415. X    if (!locate('/',file)) return(file); /* vms_name syntax */
  2416. X
  2417. X    /* search for the ':' which means a device is present */
  2418. X    device = locate(':',file);
  2419. X
  2420. X    i = 0;
  2421. X    if (device)
  2422. X      {
  2423. X          while (ch = file[i], i < device) vms_name[i++] = ch;
  2424. X      }
  2425. X    j = i;
  2426. X    
  2427. X    /* go from the  end looking for a '/' and mark it */
  2428. X    i = strlen(file) - 1;
  2429. X    while(ch = file[i], ch != '/' && i-- >= 0);
  2430. X    if (ch == '/')
  2431. X      {
  2432. X          file[i] = ']';
  2433. X          last = 0;
  2434. X      }
  2435. X    else last = 1;
  2436. X
  2437. X    i = j;
  2438. X    vms_name[j++] = '[';
  2439. X    vms_name[j++] = '.';
  2440. X    first = 0;
  2441. X    while(ch = file[i++], ch != '\0')
  2442. X      {
  2443. X          switch (ch)
  2444. X            {
  2445. X              case '.':
  2446. X                if (last) vms_name[j++] = '.';
  2447. X                if (last) break;
  2448. X                ch = file[i++];
  2449. X                if (ch == '.')
  2450. X                  {
  2451. X                      if (!first) j--;  /* overwrite the dot */
  2452. X                      vms_name[j++] = '-';
  2453. X                  }
  2454. X                else if (ch == '/'); /*  './' combinations-- do nothing */
  2455. X                else if (ch == ']')
  2456. X                  {
  2457. X                      last = 1;
  2458. X                      if (vms_name[j-1] == '.') j--;
  2459. X                      vms_name[j++] = ']';
  2460. X                  }
  2461. X                
  2462. X                else vms_name[j++] = '.';
  2463. X                break;
  2464. X              case '/':
  2465. X                if (first)
  2466. X                  {
  2467. X                      vms_name[j++] = '.';
  2468. X                  }
  2469. X                else
  2470. X                  {
  2471. X                      first = 1;
  2472. X                      /* if '/' is first char or follows a colon do nothing */
  2473. X                      if ((i!=1) && (file[i-2] != ':'))
  2474. X                        {
  2475. X                            vms_name[j++] = '.';
  2476. X                        }
  2477. X                      else j--; /* overwrite the '.' following '[' */
  2478. X                  }
  2479. X                break;
  2480. X              case ']':
  2481. X                last = 1;
  2482. X                if (vms_name[j-1] == '.') j--;
  2483. X                vms_name[j++] = ']';
  2484. X                break;
  2485. X              default:
  2486. X                vms_name[j++] = ch;
  2487. X            }
  2488. X      }
  2489. X    return (vms_name);
  2490. X}
  2491. X
  2492. X/*
  2493. main(int argc, char **argv)
  2494. X{
  2495. X    puts(unix2vms(argv[1]));
  2496. X}
  2497. X*/     
  2498. X
  2499. X#endif /* VMS */
  2500. X
  2501. X#include <time.h>
  2502. X
  2503. char *get_time()
  2504. X{ 
  2505. X    time_t clock;
  2506. X    char *the_time;
  2507. X
  2508. X    clock = time((long *) 0);
  2509. X    the_time = ctime(&clock); /* returns the form Sun Sep 16 01:03:52 1985\n\0 */
  2510. X    the_time[24] = '\0';
  2511. X    return(the_time);
  2512. X}
  2513. END_OF_FILE
  2514. if test 11684 -ne `wc -c <'sysdep.c'`; then
  2515.     echo shar: \"'sysdep.c'\" unpacked with wrong size!
  2516. fi
  2517. # end of 'sysdep.c'
  2518. fi
  2519. if test -f 'window.c' -a "${1}" != "-c" ; then 
  2520.   echo shar: Will not clobber existing file \"'window.c'\"
  2521. else
  2522. echo shar: Extracting \"'window.c'\" \(18308 characters\)
  2523. sed "s/^X//" >'window.c' <<'END_OF_FILE'
  2524. X#include <stdio.h>
  2525. X#include "externs.h"
  2526. X#include "window.h"
  2527. X#include "line.h"
  2528. X#include "display.h"
  2529. X
  2530. Window *WIN;
  2531. Window *TOP_WIN;
  2532. int COLUMN = 1;
  2533. int BEEP_MINI_B = 0;
  2534. int MINIBUFFER_SELECTED = 0;
  2535. int CURS_ROW;
  2536. int CURS_COL;
  2537. int RESTORE_WIDTH_TO = 0;
  2538. unsigned char *CURS_POS;
  2539. X
  2540. int read_string(char *str)
  2541. X{
  2542. X    char ch;
  2543. X    int i;
  2544. X
  2545. X    i = strlen(str);
  2546. X    do 
  2547. X      {
  2548. X          ch = getkey();
  2549. X          if ((ch == '\b') || (ch == 127))
  2550. X            {
  2551. X                if (i > 0)
  2552. X                  {
  2553. X                      if (str[--i] < 32) fputs("\b \b",stdout); /* erase the ^ */
  2554. X                      fputs("\b \b",stdout);
  2555. X                  }
  2556. X                else fputc('\007',stdout);
  2557. X            }
  2558. X          else if ((ch < 32) && (ch != 10) && (ch != 13))
  2559. X            {
  2560. X        if ((ch == '\007') || (ch == '\025')) /* ^G or ^U aborts */
  2561. X           {
  2562. X              fputc('\007',stdout);
  2563. X              return(-1);    /* ^G quits */
  2564. X           }
  2565. X        if (ch == '\033')  /* Allow KP ENTER as a terminator */
  2566. X           {
  2567. X              ch = getkey();
  2568. X              if (ch == 'O')
  2569. X             {
  2570. X                ch = getkey();
  2571. X                if (ch == 'M')
  2572. X                   {
  2573. X                  str[i] = '\0';
  2574. X                  return(i);
  2575. X                   }
  2576. X                else
  2577. X                   {
  2578. X                   fputc('^',stdout);
  2579. X                   fputc('[',stdout);
  2580. X                   fputc(str[i++] = 'O', stdout);
  2581. X                   fputc(str[i++] = ch, stdout);
  2582. X                   }
  2583. X             }
  2584. X              else
  2585. X             {
  2586. X                fputc('^',stdout);
  2587. X                fputc('[',stdout);
  2588. X                fputc(str[i++] = ch, stdout);
  2589. X             }
  2590. X           }
  2591. X        else
  2592. X           {
  2593. X              str[i++] = ch;
  2594. X              fputc('^',stdout);
  2595. X              fputc(ch + '@',stdout);
  2596. X           }
  2597. X            }
  2598. X          else if (ch == '`')   /* quoted insert */
  2599. X            {
  2600. X                ch = getkey();
  2601. X                str[i++] = ch;
  2602. X                if ((ch < ' ') || (ch == 127)) 
  2603. X                  {
  2604. X                      if (ch == 127) ch = '?'; else ch = ch + '@';
  2605. X                      fputc('^',stdout);
  2606. X                  }
  2607. X                fputc(ch,stdout);
  2608. X            }
  2609. X      else if ((ch != 10) && (ch != 13))
  2610. X            {
  2611. X                str[i++] = ch;
  2612. X                fputc(ch,stdout);
  2613. X            }
  2614. X          
  2615. X          fflush(stdout);
  2616. X      }
  2617. X    while ((ch != 10) && (ch != 13));
  2618. X      
  2619. X    str[i] = '\0';
  2620. X    return(i);
  2621. X}
  2622. X
  2623. X
  2624. void message(char *what, int how)
  2625. X{
  2626. X    strcpy(MINI_BUF,what);
  2627. X    if (how) BEEP_MINI_B = 1; else BEEP_MINI_B = 0;
  2628. X}
  2629. X
  2630. void select_minibuffer()
  2631. X{
  2632. X    if (MINIBUFFER_SELECTED) return;
  2633. X    MINIBUFFER_SELECTED = 1;
  2634. X    set_scroll_region(1,SCREEN_HEIGHT);
  2635. X    goto_rc(SCREEN_HEIGHT,1);
  2636. X    fflush(stdout);
  2637. X}
  2638. X
  2639. void exit_minibuffer()
  2640. X{
  2641. X    if (!MINIBUFFER_SELECTED) return;
  2642. X    MINIBUFFER_SELECTED = 0;
  2643. X    set_scroll_region(WIN->top,WIN->bot);
  2644. X    fflush(stdout);
  2645. X}
  2646. X
  2647. X/* put out string, expanding control chars */
  2648. void nicely_puts(char *str, FILE *fp)
  2649. X{
  2650. X    while (*str != '\0')
  2651. X      {
  2652. X          if ((*str < ' ') || (*str == 127))
  2653. X            {
  2654. X                fputc('^',fp);
  2655. X                if (*str != 127) fputc(*str + '@',fp); else fputc('?',fp);
  2656. X            }
  2657. X          else fputc(*str,fp);
  2658. X          str++;
  2659. X      }
  2660. X}
  2661. X
  2662. void put_message()
  2663. X{
  2664. X    select_minibuffer();
  2665. X    delete_line(1);
  2666. X    if (BEEP_MINI_B) fputc('\007',stdout);
  2667. X    BEEP_MINI_B = 0;
  2668. X    if (*MINI_BUF != '\0') nicely_puts((char *) MINI_BUF, stdout);
  2669. X    exit_minibuffer();
  2670. X}
  2671. X
  2672. X/* puts 'what in the minibuffer to be edited. */
  2673. X/* returns number of chars read */
  2674. int read_from_minibuffer(char *prompt, char *what)
  2675. X{
  2676. X    int i;
  2677. X    char str[132];
  2678. X    
  2679. X    select_minibuffer();
  2680. X    fputs(prompt,stdout);
  2681. X    if (*what != '\0')
  2682. X      nicely_puts(what,stdout);
  2683. X    fflush(stdout);
  2684. X    strcpy(str,what);
  2685. X    i = read_string(str);
  2686. X    if (i > 0) strcpy(what,str);
  2687. X    delete_line(1);
  2688. X    exit_minibuffer();
  2689. X    return(i);
  2690. X}
  2691. X
  2692. X    
  2693. void clear_minibuffer()
  2694. X{
  2695. X    MINI_BUF[0] = '\0';
  2696. X    BEEP_MINI_B = 0;
  2697. X    put_message();
  2698. X}
  2699. X
  2700. X
  2701. int get_scroll(int *line)
  2702. X{
  2703. X    /* line is the line we want at the topo of the window if possible */
  2704. X    int dtop, dbot,n,top,bot,wsize;
  2705. X
  2706. X    top = WIN->beg_line;
  2707. X    wsize = WIN->bot - WIN->top; /* actually 1 less than window size */
  2708. X    bot = top + wsize;
  2709. X
  2710. X    if ((*line == 1) && (top == 1))
  2711. X      {
  2712. X          message("Top of Buffer.",1);
  2713. X          return(0);
  2714. X      }
  2715. X    
  2716. X    /* handles endof file in a window */
  2717. X    if ((bot > NUM_LINES) && *line > C_LINE)
  2718. X      {
  2719. X          *line = top;
  2720. X          message("End of Buffer.",1);
  2721. X          return(0);
  2722. X      }
  2723. X    
  2724. X    if (NUM_LINES <= wsize)     /* short file */
  2725. X      {
  2726. X          *line = 1;
  2727. X          return(0);
  2728. X      }
  2729. X
  2730. X    dtop = top - 1;
  2731. X    dbot = NUM_LINES - bot;
  2732. X    n = *line - top;
  2733. X
  2734. X    if ((n>0) && (dbot < n))
  2735. X      {
  2736. X          n = dbot;
  2737. X          *line = top + n;
  2738. X          if (!n) message("End of buffer.",1);
  2739. X      }
  2740. X    else if ((n < 0) && (dtop + n < 0))
  2741. X      {
  2742. X          n = -dtop;
  2743. X          if (!n) message("Top of buffer.",1);
  2744. X          *line = n + top;
  2745. X      }
  2746. X    return(n);
  2747. X}
  2748. X
  2749. X
  2750. void update_window(int line)
  2751. X{
  2752. X    int n,max_n, save_line, save_col, npos;
  2753. X    unsigned char *save_pos;
  2754. X
  2755. X    if (COLUMN != WIN->col)
  2756. X      {
  2757. X          if (COLUMN < 1) COLUMN = 1;
  2758. X          if (COLUMN != WIN->col)
  2759. X            {
  2760. X                save_pos = CURS_POS; save_line = CURS_ROW; save_col = CURS_COL;
  2761. X                redraw_window();
  2762. X                update_status(0);
  2763. X                WIN->curs_pos = CURS_POS = save_pos;
  2764. X                WIN->curs_line = CURS_ROW = save_line;
  2765. X                WIN->curs_col = CURS_COL = save_col;
  2766. X            }
  2767. X          return;
  2768. X      }
  2769. X
  2770. X    
  2771. X    n = get_scroll(&line);
  2772. X    max_n = WIN->bot - WIN->top;
  2773. X    if (abs(n) > max_n)
  2774. X      {
  2775. X          goto_line(line);
  2776. X          redraw_window();
  2777. X          update_status(0);
  2778. X          return;
  2779. X      }
  2780. X    if (!n) return;
  2781. X
  2782. X    goto_rc(1,1);
  2783. X    forward_line(n);
  2784. X    WIN->beg_pos = C_POS;
  2785. X    WIN->beg_line = C_LINE;
  2786. X
  2787. X    if (n>0)
  2788. X      {
  2789. X          npos = 1;
  2790. X          delete_nlines(n);
  2791. X          goto_rc(WIN->bot - WIN->top - n + 2,1);
  2792. X          forward_line(max_n - n + 1);
  2793. X      }
  2794. X    else
  2795. X      {
  2796. X          npos = 0;
  2797. X          CURS_ROW = 1; CURS_COL = 1; CURS_POS = C_POS;
  2798. X          n = -n;
  2799. X          reverse_index(n);
  2800. X      }
  2801. X    n = n - 1;
  2802. X    display_line();
  2803. X    while(n--)
  2804. X      {
  2805. X          forward_line(1);
  2806. X          fputc('\n',stdout);
  2807. X          display_line();
  2808. X      }
  2809. X    if (npos) 
  2810. X      {
  2811. X          
  2812. X          CURS_ROW = C_LINE - WIN->beg_line + 1;
  2813. X          CURS_COL = 1; CURS_POS = C_POS;
  2814. X      }
  2815. X    
  2816. X    C_POS = WIN->beg_pos;
  2817. X    C_LINE = WIN->beg_line;
  2818. X    update_status(0);
  2819. X    fflush(stdout);
  2820. X}
  2821. X
  2822. X/* updates current window as well as scroll lock ones */
  2823. X/* Although current window is update in an absolute fashion, scroll locked
  2824. X   ones are updated in a relative fashion */
  2825. void update_windows(int line)
  2826. X{
  2827. X    int dline,flg;
  2828. X    Window *w;
  2829. X    
  2830. X    dline = line - C_LINE;
  2831. X    update_window(line);
  2832. X    if (!WIN->lock) return;
  2833. X    flg = 0;
  2834. X    w = WIN;
  2835. X    while(WIN = WIN->next, WIN != w)
  2836. X      {
  2837. X          if (WIN->lock)
  2838. X            {
  2839. X                flg = 1;
  2840. X                set_window(WIN);
  2841. X                line = C_LINE + dline;
  2842. X                update_window(line);
  2843. X            }
  2844. X      }
  2845. X    WIN = w;
  2846. X    if (flg) set_window(WIN);
  2847. X}
  2848. X
  2849. X
  2850. void redraw_window()
  2851. X{
  2852. X    int n,t;
  2853. X    t = WIN->top;
  2854. X    if (t == 1) clear_window();
  2855. X    goto_rc(1, 1);
  2856. X    n = WIN->bot - WIN->top;
  2857. X    if ((C_LINE + n) > NUM_LINES) goto_line(NUM_LINES - n);
  2858. X    WIN->curs_pos = CURS_POS = WIN->beg_pos = C_POS;
  2859. X    WIN->beg_line = C_LINE;
  2860. X    WIN->col = COLUMN;
  2861. X    WIN->curs_col = CURS_COL = 1;
  2862. X    WIN->curs_line = CURS_ROW = 1;
  2863. X    if (t != 1) delete_line(1);
  2864. X    display_line();
  2865. X    while(n--)
  2866. X      {
  2867. X          fputc('\n',stdout);
  2868. X          if (t != 1) delete_line(1);
  2869. X          if (forward_line(1)) display_line();
  2870. X      }
  2871. X    
  2872. X        
  2873. X    C_POS = WIN->beg_pos;
  2874. X    C_LINE = WIN->beg_line;
  2875. X}
  2876. X
  2877. X/* associates current window with current buffer */
  2878. void save_win_flags(Window *w)
  2879. X{
  2880. X    w->flags = 0;
  2881. X    if (MOST_V_OPT) w->flags |= _MOST_V_OPT;
  2882. X    if (MOST_B_OPT) w->flags |= _MOST_B_OPT;
  2883. X    if (MOST_T_OPT) w->flags |= _MOST_T_OPT;
  2884. X    if (MOST_W_OPT) w->flags |= _MOST_W_OPT;
  2885. X    if (SQUEEZE_LINES) w->flags |= _MOST_SQ_OPT;
  2886. X    w->n_lines = NUM_LINES;
  2887. X    w->display = MOST_S_OPT;
  2888. X}
  2889. X
  2890. void window_buffer()
  2891. X{
  2892. X    WIN->beg_line = C_LINE;
  2893. X    WIN->beg_pos = C_POS;
  2894. X    WIN->col = COLUMN;
  2895. X    WIN->buf = BUF;
  2896. X    MOST_S_OPT = 0;
  2897. X    save_win_flags(WIN);
  2898. X}
  2899. X
  2900. void clear_window()
  2901. X{
  2902. X    int i,n;
  2903. X    i = WIN->top;
  2904. X    n = WIN->bot - WIN->top;
  2905. X    if (i == 1)
  2906. X      {
  2907. X          goto_rc(WIN->bot - WIN->top + 1,SCREEN_WIDTH);
  2908. X          clr_bos();
  2909. X      }
  2910. X    else
  2911. X      {
  2912. X          goto_rc(i - WIN->top + 1,1);
  2913. X          delete_line(1);
  2914. X          while(n--)
  2915. X            {
  2916. X                fputc('\n',stdout);
  2917. X                delete_line(1);
  2918. X            }
  2919. X      }
  2920. X    
  2921. X    goto_rc(i - WIN->top + 1,1);
  2922. X    fflush(stdout);
  2923. X}
  2924. X
  2925. void restore_win_flags()
  2926. X{
  2927. X    MOST_V_OPT = WIN->flags & _MOST_V_OPT;
  2928. X    MOST_B_OPT = WIN->flags & _MOST_B_OPT;
  2929. X    MOST_T_OPT = WIN->flags & _MOST_T_OPT;
  2930. X    MOST_W_OPT = WIN->flags & _MOST_W_OPT;
  2931. X    SQUEEZE_LINES = WIN->flags & _MOST_SQ_OPT;
  2932. X    NUM_LINES = WIN->n_lines;
  2933. X    MOST_S_OPT = WIN->display;
  2934. X}
  2935. X
  2936. X
  2937. Window *make_window(int r1,int r2)
  2938. X{
  2939. X    int i;
  2940. X    Window *new;
  2941. X    new = (Window *) malloc(sizeof(Window));
  2942. X    new->status = (char *) malloc(135);
  2943. X    for (i = 0; i <= SCREEN_WIDTH; i++) new->status[i] = '\0';
  2944. X    new->col = COLUMN;
  2945. X    new->top = r1;
  2946. X    new->bot = r2;
  2947. X    new->lock = 0;
  2948. X    save_win_flags(new);
  2949. X    return(new);
  2950. X}
  2951. X
  2952. void init_display()
  2953. X{
  2954. X    int i;
  2955. X    fputs("\033[?6h",stdout);
  2956. X    TOP_WIN = WIN = make_window(1,SCREEN_HEIGHT - 2);
  2957. X    WIN->prev = WIN->next = WIN;
  2958. X    cls();
  2959. X    set_scroll_region(WIN->top, WIN->bot);
  2960. X    goto_rc(1,1);
  2961. X    fflush(stdout);
  2962. X}
  2963. X
  2964. void reset_display()
  2965. X{
  2966. X    set_scroll_region(1,SCREEN_HEIGHT);
  2967. X    fputs("\033[?6l",stdout);   /* normal origin mode */
  2968. X    goto_rc(SCREEN_HEIGHT,1);
  2969. X    if (RESTORE_WIDTH_TO)
  2970. X      {
  2971. X          set_width(RESTORE_WIDTH_TO, 0);
  2972. X          RESTORE_WIDTH_TO = 0;
  2973. X      }
  2974. X    
  2975. X    fflush(stdout);
  2976. X}
  2977. X
  2978. update_status1(int new_status)
  2979. X{
  2980. X    char str[30], ch, *strp;
  2981. X    static char new[135];
  2982. X    int i,ii,r,x,line_p = 60;
  2983. X
  2984. X    r = WIN->bot + 1;
  2985. X    goto_rc(r,1);
  2986. X
  2987. X    i = ii = 0;
  2988. X    new[ii++] = '-';
  2989. X    if (WIN->lock) new[ii++] = '*'; else new[ii++] = '-';
  2990. X    strp = " MOST: ";
  2991. X    while(*strp != '\0') new[ii++] = *strp++;
  2992. X    
  2993. X    while(ch = WIN->buf->file[i++], ch != '\0') new[ii++] = ch;
  2994. X
  2995. X    while(ii < line_p) new[ii++] = ' ';
  2996. X
  2997. X    x = (C_LINE + WIN->bot - WIN->top) * 100; x = x / NUM_LINES;
  2998. X
  2999. X    /* for files with end of file above the bottom row (due to window manipulations) */
  3000. X    if (x > 100) x = 100;
  3001. X    sprintf(str,"(%d,%d) %d%%",C_LINE,COLUMN,x);
  3002. X    i = 0; while(ch = str[i++], ch != '\0') new[ii++] = ch;
  3003. X
  3004. X    while(ii < SCREEN_WIDTH) new[ii++] = '-';
  3005. X    new[SCREEN_WIDTH] = '\0';
  3006. X    set_attribute(7);
  3007. X    if (new_status)
  3008. X      fputs(new,stdout);
  3009. X    else
  3010. X      smart_puts(new,WIN->status,stdout);
  3011. X    set_attribute(0);
  3012. X    strcpy(WIN->status,new);
  3013. X}
  3014. X
  3015. void update_status(int new_status)
  3016. X{
  3017. X
  3018. X    C_LINE = WIN->beg_line;
  3019. X    C_POS = WIN->beg_pos;
  3020. X    set_scroll_region(1,SCREEN_HEIGHT);
  3021. X    update_status1(new_status);
  3022. X    set_scroll_region(WIN->top,WIN->bot);
  3023. X    fflush(stdout);
  3024. X}
  3025. X
  3026. X/* splits window-- no screen update, does not affect scrolling region */
  3027. int split_window()
  3028. X{
  3029. X    Window *new, *old;
  3030. X    int b2,t2,b1, line;
  3031. X
  3032. X    b2 = WIN->bot;
  3033. X    b1 = (WIN->bot + WIN->top) / 2 - 1;
  3034. X    t2 = b1 + 2;
  3035. X    if ((b1 == WIN->top) || (t2 == b2)) return(0);
  3036. X
  3037. X    /* line is top line of new window. */
  3038. X    line = WIN->beg_line + t2 - WIN->top;
  3039. X    old = WIN;
  3040. X    WIN->bot = b1;
  3041. X    new = make_window(t2,b2);
  3042. X    /* add to ring */
  3043. X    WIN->next->prev = new;
  3044. X    new->next = WIN->next;
  3045. X    new->prev = WIN;
  3046. X    WIN->next = new;
  3047. X
  3048. X    new->beg_line = line;
  3049. X    new->buf = BUF;
  3050. X    /* new window status line is at same position as old */
  3051. X    strcpy(new->status,WIN->status);
  3052. X    return(1);
  3053. X}
  3054. X
  3055. X    
  3056. void two_windows()
  3057. X{
  3058. X    int line;
  3059. X    Window *new, *old;
  3060. X    if (!split_window()) return;
  3061. X
  3062. X    old = WIN;
  3063. X    new = WIN->next;
  3064. X    line = new->beg_line;
  3065. X    if (line + new->bot - new->top > NUM_LINES)
  3066. X      {
  3067. X          other_window(1);
  3068. X          /* since split window left new window undefined... */
  3069. X          C_POS = old->beg_pos;
  3070. X          C_LINE = old->beg_line;
  3071. X          if (NUM_LINES <= new->bot - new->top + 1)
  3072. X            {
  3073. X                C_LINE = new->beg_line = 1;
  3074. X                C_POS = new->beg_pos = BUF->beg;
  3075. X                redraw_window();
  3076. X                update_status(0);
  3077. X            }
  3078. X          else if (line > NUM_LINES)
  3079. X            {
  3080. X                goto_line(NUM_LINES - new->bot + new->top);
  3081. X                WIN->beg_pos = C_POS;
  3082. X                WIN->beg_line = C_LINE;
  3083. X                redraw_window();
  3084. X                update_status(0);
  3085. X            }    
  3086. X          else
  3087. X            {
  3088. X                goto_line(line);
  3089. X                WIN->beg_pos = C_POS;
  3090. X                WIN->beg_line = C_LINE;
  3091. X                update_window(NUM_LINES - new->bot + new->top);
  3092. X            }
  3093. X          WIN->curs_line = 1;
  3094. X          WIN->curs_col = COLUMN;
  3095. X          WIN->curs_pos = C_POS;
  3096. X          other_window(-1);
  3097. X      }
  3098. X    else
  3099. X      {
  3100. X          WIN = new;
  3101. X          (void) forward_line(line - old->beg_line);
  3102. X          new->beg_pos = C_POS;
  3103. X          new->beg_line = C_LINE;
  3104. X          new->curs_line = 1;
  3105. X          new->curs_col = COLUMN;
  3106. X          new->curs_pos = C_POS;
  3107. X          update_status(0);
  3108. X          WIN = old;
  3109. X      }    
  3110. X    update_status(1);
  3111. X}
  3112. X
  3113. void expand_window1(int dn)
  3114. X{
  3115. X    int l, save_top, save_line;
  3116. X    unsigned char *save_pos;
  3117. X
  3118. X    /* l is line after last line of current window (where status line is) */
  3119. X    l = WIN->beg_line + WIN->bot - WIN->top + 1;
  3120. X    save_top = WIN->top;
  3121. X    WIN->top = WIN->bot + 1;
  3122. X    WIN->bot = WIN->bot + dn;
  3123. X    set_scroll_region(WIN->top, WIN->bot);
  3124. X    if (l > NUM_LINES)
  3125. X      {
  3126. X          clear_window();
  3127. X      }
  3128. X    else
  3129. X      {
  3130. X          /* should add something here for smarter scrolling...
  3131. X             if ((WIN->next->BUF == BUF) && (l >= WIN->next->beg_line)
  3132. X             && (l <= (WIN->next->beg_line + WIN->next)
  3133. X             */
  3134. X                
  3135. X          save_line = C_LINE;
  3136. X          save_pos = C_POS;
  3137. X          goto_line(l);
  3138. X          redraw_window();
  3139. X          WIN->beg_line = C_LINE = save_line;
  3140. X          WIN->beg_pos = C_POS = save_pos;
  3141. X      }
  3142. X    WIN->top = save_top;
  3143. X    set_scroll_region(WIN->top, WIN->bot);
  3144. X}
  3145. X
  3146. void one_window()
  3147. X{
  3148. X    Window *w, *tmp;
  3149. X    int diff;
  3150. X    
  3151. X    if (WIN->next == WIN) return;
  3152. X    w = WIN;
  3153. X    WIN = WIN->next;
  3154. X    /* delete other windows preserving the ring! */
  3155. X    while(WIN != w)
  3156. X      {
  3157. X          free_window_buffer(); /* needs a ring */
  3158. X          tmp = WIN->next;
  3159. X          /* if this is the bottom window, save its status line */
  3160. X          if (tmp == TOP_WIN) strcpy(w->status,WIN->status);
  3161. X          tmp->prev = WIN->prev;
  3162. X          WIN->prev->next = tmp;
  3163. X          free(WIN);
  3164. X          WIN = tmp;
  3165. X      }
  3166. X    WIN = w;
  3167. X    /* slide the window to the top and expand it */
  3168. X    diff = WIN->top - 1;
  3169. X    if (diff)
  3170. X      {
  3171. X          set_scroll_region(1,SCREEN_HEIGHT - 2);
  3172. X          goto_rc(1,1);
  3173. X          delete_nlines(diff);
  3174. X          WIN->top = 1;
  3175. X          WIN->bot -=  diff;
  3176. X          TOP_WIN = WIN;
  3177. X      }
  3178. X    expand_window1(SCREEN_HEIGHT - 2 - WIN->bot);
  3179. X    update_status(0);
  3180. X}
  3181. X
  3182. X          
  3183. void set_window(Window *w)
  3184. X{
  3185. X    WIN = w;
  3186. X    CURS_ROW = WIN->curs_line;
  3187. X    CURS_COL = WIN->curs_col;
  3188. X    CURS_POS = WIN->curs_pos;
  3189. X    C_LINE = WIN->beg_line;
  3190. X    C_POS = WIN->beg_pos;
  3191. X    COLUMN = WIN->col;
  3192. X    BUF = WIN->buf;
  3193. X    switch_to_buffer(BUF);
  3194. X    set_scroll_region(WIN->top,WIN->bot);
  3195. X    restore_win_flags();
  3196. X    fflush(stdout);
  3197. X}
  3198. X
  3199. void other_window(int n)
  3200. X{
  3201. X    if (!n) return;
  3202. X    WIN->beg_pos = C_POS;
  3203. X    WIN->curs_pos = CURS_POS;
  3204. X    WIN->curs_line = CURS_ROW;
  3205. X    WIN->curs_col = CURS_COL;
  3206. X    WIN->beg_line = C_LINE;
  3207. X    save_win_flags(WIN);
  3208. X    if (n < 0)
  3209. X      while (n++) WIN = WIN->prev;
  3210. X    else
  3211. X      while (n--) WIN = WIN->next;
  3212. X    set_window(WIN);
  3213. X}
  3214. X
  3215. X
  3216. X
  3217. X/* kills window by moving lower window up */
  3218. delete_as_top_window()
  3219. X{
  3220. X    int t1,t2,b1,b2;
  3221. X    t1 = WIN->top;
  3222. X    t2 = WIN->next->top;
  3223. X    b1 = WIN->bot;
  3224. X    b2 = WIN->next->bot;
  3225. X    WIN->prev->next = WIN->next;
  3226. X    WIN->next->prev = WIN->prev;
  3227. X
  3228. X    /* scroll contents of window below to top */
  3229. X    set_scroll_region(t1,b2);
  3230. X    goto_rc(1,1);
  3231. X    delete_nlines(t2 - t1);
  3232. X    other_window(1);
  3233. X    WIN->top = t1;
  3234. X    WIN->bot = b2 - t2 + t1;
  3235. X    expand_window1(b2 - WIN->bot);
  3236. X    update_status(0);
  3237. X}
  3238. X
  3239. X/* free buffer for this window if no other windows are viewing it. */
  3240. free_window_buffer()
  3241. X{
  3242. X    Window *w;
  3243. X    int f = 1;
  3244. X    w = WIN;
  3245. X    WIN = w->next;
  3246. X    while((WIN != w) && f)
  3247. X      {
  3248. X          if (!strcmp(WIN->buf->file,w->buf->file)) f = 0;
  3249. X          WIN = WIN->next;
  3250. X      }
  3251. X    WIN = w;
  3252. X    if (f) free(WIN->buf);
  3253. X}
  3254. X
  3255. X
  3256. delete_window()
  3257. X{
  3258. X    int new_b, old_b;
  3259. X    Window *w;
  3260. X    
  3261. X    w = WIN;
  3262. X    if (WIN->next == WIN) return;
  3263. X    free_window_buffer();
  3264. X    if (WIN->next != TOP_WIN)
  3265. X      {
  3266. X          if (WIN == TOP_WIN)
  3267. X            {
  3268. X                delete_as_top_window();
  3269. X                TOP_WIN = WIN;  /* not anymore, this one is */
  3270. X            }
  3271. X          else
  3272. X            delete_as_top_window();
  3273. X          
  3274. X          free(w);
  3275. X          return;
  3276. X      }
  3277. X    old_b = WIN->top - 2;
  3278. X    new_b = WIN->bot;
  3279. X    other_window(-1);
  3280. X    expand_window1(new_b - old_b);
  3281. X    strcpy(WIN->status,w->status); /* share the same line */
  3282. X    
  3283. X    WIN->next = w->next;
  3284. X    WIN->next->prev = WIN;
  3285. X    free(w);
  3286. X    update_status(0);
  3287. X}
  3288. X
  3289. void redraw_display()
  3290. X{
  3291. X    Window *w;
  3292. X    int n,t;
  3293. X    fputs("\033[?6h",stdout);   /* relative origins */
  3294. X    set_scroll_region(1,SCREEN_HEIGHT);
  3295. X    cls();
  3296. X    save_win_flags(WIN);
  3297. X    w = WIN;
  3298. X    do
  3299. X      {
  3300. X          WIN = WIN->next;
  3301. X          t = WIN->top;
  3302. X          goto_rc(t, 1);
  3303. X          C_POS = WIN->beg_pos;
  3304. X          C_LINE = WIN->beg_line;
  3305. X          COLUMN = WIN->col;
  3306. X          switch_to_buffer(WIN->buf);
  3307. X          restore_win_flags();
  3308. X          n = WIN->bot - WIN->top;
  3309. X          display_line();
  3310. X          while(n--)
  3311. X            {
  3312. X                fputc('\n',stdout);
  3313. X                if (forward_line(1)) display_line();
  3314. X            }
  3315. X          C_LINE = WIN->beg_line;
  3316. X          C_POS = WIN->beg_pos;
  3317. X          update_status1(1);
  3318. X      }
  3319. X    while(WIN != w);
  3320. X    set_window(w);
  3321. X}
  3322. X
  3323. void toggle_lock()
  3324. X{
  3325. X    WIN->lock = !(WIN->lock);
  3326. X    update_status(0);
  3327. X}
  3328. END_OF_FILE
  3329. if test 18308 -ne `wc -c <'window.c'`; then
  3330.     echo shar: \"'window.c'\" unpacked with wrong size!
  3331. fi
  3332. # end of 'window.c'
  3333. fi
  3334. echo shar: End of archive 2 \(of 2\).
  3335. cp /dev/null ark2isdone
  3336. MISSING=""
  3337. for I in 1 2 ; do
  3338.     if test ! -f ark${I}isdone ; then
  3339.     MISSING="${MISSING} ${I}"
  3340.     fi
  3341. done
  3342. if test "${MISSING}" = "" ; then
  3343.     echo You have unpacked both archives.
  3344.     rm -f ark[1-9]isdone
  3345. else
  3346.     echo You still need to unpack the following archives:
  3347.     echo "        " ${MISSING}
  3348. fi
  3349. ##  End of shell archive.
  3350. exit 0
  3351.